src/Sylius/Bundle/UiBundle/Block/BlockEventListener.php line 29

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\UiBundle\Block;
  12. use Sonata\BlockBundle\Event\BlockEvent;
  13. use Sonata\BlockBundle\Model\Block;
  14. final class BlockEventListener
  15. {
  16.     /** @var string */
  17.     private $template;
  18.     public function __construct(string $template)
  19.     {
  20.         $this->template $template;
  21.     }
  22.     public function onBlockEvent(BlockEvent $event): void
  23.     {
  24.         $block = new Block();
  25.         $block->setId(uniqid(''true));
  26.         $block->setSettings(array_replace($event->getSettings(), [
  27.             'template' => $this->template,
  28.         ]));
  29.         $block->setType('sonata.block.service.template');
  30.         $event->addBlock($block);
  31.     }
  32. }