vendor/pimcore/pimcore/bundles/CoreBundle/EventListener/Frontend/DocumentRendererListener.php line 50

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Bundle\CoreBundle\EventListener\Frontend;
  15. use Pimcore\Event\DocumentEvents;
  16. use Pimcore\Twig\Extension\Templating\Placeholder\ContainerService;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. /**
  19.  * Handles block state for sub requests (saves parent state and restores it after request completes)
  20.  *
  21.  * @internal
  22.  */
  23. class DocumentRendererListener implements EventSubscriberInterface
  24. {
  25.     public function __construct(protected ContainerService $containerService)
  26.     {
  27.     }
  28.     /**
  29.      * {@inheritdoc}
  30.      */
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [
  34.             DocumentEvents::RENDERER_PRE_RENDER => 'onPreRender',
  35.             DocumentEvents::RENDERER_POST_RENDER => 'onPostRender',
  36.         ];
  37.     }
  38.     public function onPreRender()
  39.     {
  40.         // when rendering a new document, the index is pushed to create a new, empty context
  41.         $this->containerService->pushIndex();
  42.     }
  43.     public function onPostRender()
  44.     {
  45.         $this->containerService->popIndex();
  46.     }
  47. }