Last active
November 10, 2022 13:16
-
-
Save arfaram/9604e7c7822f71106bbdf5f8bd170369 to your computer and use it in GitHub Desktop.
Ibexa4 - Force Display pagebuilder blocks Listener and Twig errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace AppBundle\EventSubscriber\Blocks; | |
use Ibexa\FieldTypePage\Event\BlockResponseEvent; | |
use Ibexa\FieldTypePage\Event\BlockResponseEvents; | |
use Ibexa\FieldTypePage\Exception\BlockRenderException; | |
use Ibexa\FieldTypePage\FieldType\Page\Service\BlockService; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
class BlockResponseSubscriber implements EventSubscriberInterface | |
{ | |
/** @var BlockService */ | |
private $blockService; | |
public function __construct( | |
BlockService $blockService, | |
) { | |
$this->blockService = $blockService; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public static function getSubscribedEvents() | |
{ | |
return [ | |
BlockResponseEvents::BLOCK_RESPONSE => ['onBlockResponse', 300], | |
]; | |
} | |
/** | |
* @param \Ibexa\FieldTypePage\Event\BlockResponseEvent $event | |
* | |
* @throws \Exception | |
*/ | |
public function onBlockResponse(BlockResponseEvent $event): void | |
{ | |
$response = $event->getResponse(); | |
try { | |
$response->setContent($this->blockService->render($event->getBlockContext(), $event->getBlockValue())); | |
} catch (\Exception $e) { | |
throw new BlockRenderException($event->getBlockValue()->getType(), $e->getMessage() . $e->getFile().':'.$e->getLine()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment