<?php
namespace App\Twig\WebContent;
use App\Repository\Interfaces\HotelRepositoryInterface;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Twig\Environment;
use Twig\TwigFunction;
use WAM\Bundle\WebContentBundle\Repository\Interfaces\MenuItemRepositoryInterface;
use WAM\Bundle\WebContentBundle\Twig\MenuExtension as CoreMenuExtension;
/**
* Twig extension to render all items form a menu.
*
* @author Edgar Tébar <etebar@wearemarketing.com>
*/
class MenuExtension extends CoreMenuExtension
{
private CoreMenuExtension $decoratedExtension;
private HotelRepositoryInterface $hotelRepository;
public function __construct(CoreMenuExtension $decoratedExtension, HotelRepositoryInterface $hotelRepository)
{
$this->decoratedExtension = $decoratedExtension;
$this->hotelRepository = $hotelRepository;
}
public function renderMenu(Environment $twig, string $menu, array $options = [])
{
if ($menu == 'TOP') {
$options = array_merge($options, array(
'hotels' => $this->hotelRepository->getAllSortedByCity(),
));
}
return $this->decoratedExtension->renderMenu($twig, $menu, $options);
}
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName()
{
return 'wam.menu.twig.extension';
}
}