vendor/contao-bootstrap/grid/src/Listener/BuildContextConfigListener.php line 39

Open in your IDE?
  1. <?php
  2. /**
  3.  * Contao Bootstrap grid.
  4.  *
  5.  * @package    contao-bootstrap
  6.  * @subpackage Grid
  7.  * @author     David Molineus <david.molineus@netzmacht.de>
  8.  * @author     Patrick Landolt <patrick.landolt@artack.ch>
  9.  * @copyright  2017-2020 netzmacht David Molineus. All rights reserved.
  10.  * @license    https://github.com/contao-bootstrap/grid/blob/master/LICENSE LGPL 3.0-or-later
  11.  * @filesource
  12.  */
  13. declare(strict_types=1);
  14. namespace ContaoBootstrap\Grid\Listener;
  15. use Contao\StringUtil;
  16. use Contao\ThemeModel;
  17. use ContaoBootstrap\Core\Config\ArrayConfig;
  18. use ContaoBootstrap\Core\Environment\ThemeContext;
  19. use ContaoBootstrap\Core\Message\Command\BuildContextConfig;
  20. /**
  21.  * Class BuildContextConfigListener.
  22.  *
  23.  * @package ContaoBootstrap\Grid\Message\Subscriber
  24.  */
  25. class BuildContextConfigListener
  26. {
  27.     /**
  28.      * Build theme config.
  29.      *
  30.      * @param BuildContextConfig $command Command.
  31.      *
  32.      * @return void
  33.      */
  34.     public function buildThemeConfig(BuildContextConfig $command): void
  35.     {
  36.         $context $command->getContext();
  37.         if (!$context instanceof ThemeContext) {
  38.             return;
  39.         }
  40.         $theme ThemeModel::findByPk($context->getThemeId());
  41.         if (!$theme instanceof ThemeModel) {
  42.             return;
  43.         }
  44.         $config $command->getConfig();
  45.         $data   $config->get([]);
  46.         if ($theme->bs_grid_columns) {
  47.             $data['grid']['columns'] = (int) $theme->bs_grid_columns;
  48.         }
  49.         if ($theme->bs_grid_sizes) {
  50.             $data['grid']['sizes'] = StringUtil::deserialize($theme->bs_grid_sizestrue);
  51.         }
  52.         if ($theme->bs_grid_default_size) {
  53.             $data['grid']['default_size'] = $theme->bs_grid_default_size ?: current($data['grid']['sizes']);
  54.         }
  55.         $command->setConfig(new ArrayConfig($data));
  56.     }
  57. }