vendor/kevinpapst/adminlte-bundle/Controller/BreadcrumbController.php line 33

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the AdminLTE bundle.
  4.  *
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace KevinPapst\AdminLTEBundle\Controller;
  9. use KevinPapst\AdminLTEBundle\Event\BreadcrumbMenuEvent;
  10. use KevinPapst\AdminLTEBundle\Event\SidebarMenuEvent;
  11. use KevinPapst\AdminLTEBundle\Model\MenuItemInterface;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. /**
  15.  * Controller to handle breadcrumb display inside the layout
  16.  */
  17. class BreadcrumbController extends EmitterController
  18. {
  19.     /**
  20.      * Controller Reference action to be called inside the layout.
  21.      *
  22.      * Triggers the {@link BreadcrumbMenuEvent} to receive the currently active menu chain.
  23.      *
  24.      * If there are no listeners attached for this event, the return value is an empty response.
  25.      *
  26.      * @param Request $request
  27.      * @return Response
  28.      */
  29.     public function breadcrumbAction(Request $request): Response
  30.     {
  31.         if (!$this->hasListener(BreadcrumbMenuEvent::class)) {
  32.             return new Response();
  33.         }
  34.         /** @var SidebarMenuEvent $event */
  35.         $event $this->dispatch(new BreadcrumbMenuEvent($request));
  36.         /** @var MenuItemInterface $active */
  37.         $active $event->getActive();
  38.         $list = [];
  39.         if (null !== $active) {
  40.             $list[] = $active;
  41.             while (null !== ($item $active->getActiveChild())) {
  42.                 $list[] = $item;
  43.                 $active $item;
  44.             }
  45.         }
  46.         return $this->render('@AdminLTE/Breadcrumb/breadcrumb.html.twig', [
  47.             'active' => $list,
  48.         ]);
  49.     }
  50. }