vendor/ibexa/form-builder/src/lib/Block/FormBlockListener.php line 47

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\FormBuilder\Block;
  8. use Ibexa\Contracts\Core\Repository\ContentService;
  9. use Ibexa\FieldTypePage\FieldType\Page\Block\Renderer\BlockRenderEvents;
  10. use Ibexa\FieldTypePage\FieldType\Page\Block\Renderer\Event\PreRenderEvent;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. class FormBlockListener implements EventSubscriberInterface
  13. {
  14.     /** @var \Ibexa\Contracts\Core\Repository\ContentService */
  15.     private $contentService;
  16.     /**
  17.      * EmbedBlockListener constructor.
  18.      *
  19.      * @param \Ibexa\Contracts\Core\Repository\ContentService $contentService
  20.      */
  21.     public function __construct(ContentService $contentService)
  22.     {
  23.         $this->contentService $contentService;
  24.     }
  25.     /**
  26.      * @return array The event names to listen to
  27.      */
  28.     public static function getSubscribedEvents()
  29.     {
  30.         return [
  31.             BlockRenderEvents::getBlockPreRenderEventName('form') => 'onBlockPreRender',
  32.         ];
  33.     }
  34.     /**
  35.      * @param \Ibexa\FieldTypePage\FieldType\Page\Block\Renderer\Event\PreRenderEvent $event
  36.      *
  37.      * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
  38.      * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
  39.      */
  40.     public function onBlockPreRender(PreRenderEvent $event)
  41.     {
  42.         $blockValue $event->getBlockValue();
  43.         $renderRequest $event->getRenderRequest();
  44.         $parameters $renderRequest->getParameters();
  45.         $contentIdAttribute $blockValue->getAttribute('contentId');
  46.         $contentInfo $this->contentService->loadContentInfo($contentIdAttribute->getValue());
  47.         $parameters['locationId'] = $contentInfo->mainLocationId;
  48.         $renderRequest->setParameters($parameters);
  49.     }
  50. }
  51. class_alias(FormBlockListener::class, 'EzSystems\EzPlatformFormBuilder\Block\FormBlockListener');