vendor/sylius/sylius/src/Sylius/Bundle/UiBundle/Block/BlockEventListener.php line 27

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. /**
  15.  * @deprecated
  16.  */
  17. final class BlockEventListener
  18. {
  19.     /** @var string */
  20.     private $template;
  21.     public function __construct(string $template)
  22.     {
  23.         @trigger_error(
  24.             sprintf('Using "%s" to add blocks to the templates is deprecated since Sylius 1.7 and will be removed in Sylius 2.0. Use "sylius_ui" configuration instead.'self::class),
  25.             \E_USER_DEPRECATED
  26.         );
  27.         $this->template $template;
  28.     }
  29.     public function onBlockEvent(BlockEvent $event): void
  30.     {
  31.         $block = new Block();
  32.         $block->setId(uniqid(''true));
  33.         $block->setSettings(array_replace($event->getSettings(), [
  34.             'template' => $this->template,
  35.         ]));
  36.         $block->setType('sonata.block.service.template');
  37.         $event->addBlock($block);
  38.     }
  39. }