vendor/ibexa/page-builder/src/lib/Event/Subscriber/BlockConfigurationTemplateSubscriber.php line 43

Open in your IDE?
  1. <?php
  2. /**
  3. * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4. * @license For full copyright and license information view LICENSE file distributed with this source code.
  5. */
  6. declare(strict_types=1);
  7. namespace Ibexa\PageBuilder\Event\Subscriber;
  8. use Ibexa\Core\MVC\Symfony\Event\PreContentViewEvent;
  9. use Ibexa\Core\MVC\Symfony\MVCEvents;
  10. use Ibexa\FieldTypePage\FieldType\Page\Block\Definition\BlockDefinitionFactoryInterface;
  11. use Ibexa\PageBuilder\View\BlockConfigurationView;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. class BlockConfigurationTemplateSubscriber implements EventSubscriberInterface
  14. {
  15. /** @var \Ibexa\FieldTypePage\FieldType\Page\Block\Definition\BlockDefinitionFactoryInterface */
  16. private $blockDefinitionFactory;
  17. public function __construct(
  18. BlockDefinitionFactoryInterface $blockDefinitionFactory
  19. ) {
  20. $this->blockDefinitionFactory = $blockDefinitionFactory;
  21. }
  22. /**
  23. * @return array
  24. */
  25. public static function getSubscribedEvents()
  26. {
  27. return [
  28. MVCEvents::PRE_CONTENT_VIEW => 'onPreContentView',
  29. ];
  30. }
  31. /**
  32. * @param \Ibexa\Core\MVC\Symfony\Event\PreContentViewEvent $event
  33. *
  34. * @throws \Exception
  35. */
  36. public function onPreContentView(PreContentViewEvent $event)
  37. {
  38. $view = $event->getContentView();
  39. if (!$view instanceof BlockConfigurationView) {
  40. return;
  41. }
  42. $blockIdentifier = $view->getBlockTypeIdentifier();
  43. $blockDefinition = $this->blockDefinitionFactory->getBlockDefinition($blockIdentifier);
  44. $view->setTemplateIdentifier($blockDefinition->getConfigurationTemplate());
  45. }
  46. }
  47. class_alias(BlockConfigurationTemplateSubscriber::class, 'EzSystems\EzPlatformPageBuilder\Event\Subscriber\BlockConfigurationTemplateSubscriber');