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

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.     private string $template;
  20.     public function __construct(string $template)
  21.     {
  22.         @trigger_error(
  23.             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),
  24.             \E_USER_DEPRECATED
  25.         );
  26.         $this->template $template;
  27.     }
  28.     public function onBlockEvent(BlockEvent $event): void
  29.     {
  30.         $block = new Block();
  31.         $block->setId(uniqid(''true));
  32.         $block->setSettings(array_replace($event->getSettings(), [
  33.             'template' => $this->template,
  34.         ]));
  35.         $block->setType('sonata.block.service.template');
  36.         $event->addBlock($block);
  37.     }
  38. }