vendor/ibexa/core/src/lib/MVC/Symfony/View/ParametersInjector/ValueObjectsIds.php line 25

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. namespace Ibexa\Core\MVC\Symfony\View\ParametersInjector;
  7. use Ibexa\Contracts\Core\Repository\Values\Content\Location;
  8. use Ibexa\Core\MVC\Symfony\View;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. /**
  11.  * Injects the ID of the view's value objects as view parameters.
  12.  *
  13.  * Required for backward compatibility with custom view controllers that used arguments such as locationId or contentId.
  14.  */
  15. class ValueObjectsIds implements EventSubscriberInterface
  16. {
  17.     public static function getSubscribedEvents()
  18.     {
  19.         return [View\ViewEvents::FILTER_VIEW_PARAMETERS => 'injectValueObjectsIds'];
  20.     }
  21.     public function injectValueObjectsIds(View\Event\FilterViewParametersEvent $event)
  22.     {
  23.         $view $event->getView();
  24.         $parameterBag $event->getParameterBag();
  25.         if ($view instanceof View\LocationValueView) {
  26.             if (($location $view->getLocation()) instanceof Location) {
  27.                 $parameterBag->set('locationId'$location->id);
  28.             }
  29.         }
  30.         if ($view instanceof View\ContentValueView) {
  31.             $parameterBag->set('contentId'$view->getContent()->id);
  32.         }
  33.     }
  34. }
  35. class_alias(ValueObjectsIds::class, 'eZ\Publish\Core\MVC\Symfony\View\ParametersInjector\ValueObjectsIds');