<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
namespace Ibexa\FormBuilder\Block;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\FieldTypePage\FieldType\Page\Block\Renderer\BlockRenderEvents;
use Ibexa\FieldTypePage\FieldType\Page\Block\Renderer\Event\PreRenderEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class FormBlockListener implements EventSubscriberInterface
{
/** @var \Ibexa\Contracts\Core\Repository\ContentService */
private $contentService;
/**
* EmbedBlockListener constructor.
*
* @param \Ibexa\Contracts\Core\Repository\ContentService $contentService
*/
public function __construct(ContentService $contentService)
{
$this->contentService = $contentService;
}
/**
* @return array The event names to listen to
*/
public static function getSubscribedEvents()
{
return [
BlockRenderEvents::getBlockPreRenderEventName('form') => 'onBlockPreRender',
];
}
/**
* @param \Ibexa\FieldTypePage\FieldType\Page\Block\Renderer\Event\PreRenderEvent $event
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
*/
public function onBlockPreRender(PreRenderEvent $event)
{
$blockValue = $event->getBlockValue();
$renderRequest = $event->getRenderRequest();
$parameters = $renderRequest->getParameters();
$contentIdAttribute = $blockValue->getAttribute('contentId');
$contentInfo = $this->contentService->loadContentInfo($contentIdAttribute->getValue());
$parameters['locationId'] = $contentInfo->mainLocationId;
$renderRequest->setParameters($parameters);
}
}
class_alias(FormBlockListener::class, 'EzSystems\EzPlatformFormBuilder\Block\FormBlockListener');