for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\SeoBundle\Event;
use Sonata\BlockBundle\Block\Service\BlockServiceInterface;
use Sonata\BlockBundle\Event\BlockEvent;
use Sonata\BlockBundle\Model\Block;
/**
* BreadcrumbListener for Block Event.
* @author Sylvain Deloux <[email protected]>
final class BreadcrumbListener
{
* @var array
protected $blockServices = [];
* Add a renderer to the status services list.
* @param string $type
public function addBlockService($type, BlockServiceInterface $blockService): void
$this->blockServices[$type] = $blockService;
}
* Add context related BlockService, if found.
public function onBlock(BlockEvent $event): void
$context = $event->getSetting('context', null);
if (null === $context) {
return;
foreach ($this->blockServices as $type => $blockService) {
if ($blockService->handleContext($context)) {
$block = new Block();
$block->setId(uniqid());
$block->setSettings($event->getSettings());
$block->setType($type);
$event->addBlock($block);