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

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