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

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 Enterprise License (PEL)
  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 PEL
  13.  */
  14. namespace Pimcore\Bundle\CoreBundle\EventListener\Frontend;
  15. use Pimcore\Event\DocumentEvents;
  16. use Pimcore\Templating\Helper\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. class DocumentRendererListener implements EventSubscriberInterface
  22. {
  23.     /**
  24.      * @var ContainerService
  25.      */
  26.     protected $containerService;
  27.     public function __construct(ContainerService $containerService)
  28.     {
  29.         $this->containerService $containerService;
  30.     }
  31.     /**
  32.      * @inheritDoc
  33.      */
  34.     public static function getSubscribedEvents()
  35.     {
  36.         return [
  37.             DocumentEvents::RENDERER_PRE_RENDER => 'onPreRender',
  38.             DocumentEvents::RENDERER_POST_RENDER => 'onPostRender'
  39.         ];
  40.     }
  41.     public function onPreRender()
  42.     {
  43.         // when rendering a new document, the index is pushed to create a new, empty context
  44.         $this->containerService->pushIndex();
  45.     }
  46.     public function onPostRender()
  47.     {
  48.         $this->containerService->popIndex();
  49.     }
  50. }