<?php
namespace App\EventListener;
use App\Event\PageEvent;
use App\Util\Breadcrumb;
class BreadcrumbListener
{
/**
* @var Breadcrumb
*/
private $breadcrumb;
public function __construct(Breadcrumb $breadcrumb)
{
$this->breadcrumb = $breadcrumb;
}
public function onBeforeRender(PageEvent $pageEvent)
{
$page = $pageEvent->getPage();
if (false !== mb_strpos($page->getBody(), '{breadcrumbs}')) {
$breadcrumbs = $this->breadcrumb->renderBreadcrumbsForPage($page, $page->getBreadcrumbEntity());
$page->setBody(str_replace('{breadcrumbs}', $breadcrumbs, $page->getBody()));
}
}
}