vendor/pimcore/pimcore/lib/Templating/Helper/Action.php line 92

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\Templating\Helper;
  15. use Pimcore\Model\Document\PageSnippet;
  16. use Pimcore\Targeting\Document\DocumentTargetingConfigurator;
  17. use Pimcore\Templating\Renderer\ActionRenderer;
  18. use Symfony\Component\Templating\Helper\Helper;
  19. class Action extends Helper
  20. {
  21.     /**
  22.      * @var ActionRenderer
  23.      */
  24.     protected $actionRenderer;
  25.     /**
  26.      * @var DocumentTargetingConfigurator
  27.      */
  28.     private $targetingConfigurator;
  29.     /**
  30.      * @var array
  31.      */
  32.     private $routingDefaults = [];
  33.     public function __construct(
  34.         ActionRenderer $actionRenderer,
  35.         DocumentTargetingConfigurator $targetingConfigurator
  36.     ) {
  37.         $this->actionRenderer $actionRenderer;
  38.         $this->targetingConfigurator $targetingConfigurator;
  39.     }
  40.     public function setRoutingDefaults(array $routingDefaults)
  41.     {
  42.         $this->routingDefaults $routingDefaults;
  43.     }
  44.     /**
  45.      * @inheritDoc
  46.      */
  47.     public function getName()
  48.     {
  49.         return 'action';
  50.     }
  51.     /**
  52.      * @param string $action
  53.      * @param string $controller
  54.      * @param string|null $module
  55.      * @param array $attributes
  56.      * @param array $query
  57.      * @param array $options
  58.      *
  59.      * @return string
  60.      */
  61.     public function __invoke($action$controller$module null, array $attributes = [], array $query = [], array $options = [])
  62.     {
  63.         $document = isset($attributes['document']) ? $attributes['document'] : null;
  64.         if ($document && $document instanceof PageSnippet) {
  65.             // apply best matching target group (if any)
  66.             $this->targetingConfigurator->configureTargetGroup($document);
  67.             $attributes $this->actionRenderer->addDocumentAttributes($document$attributes);
  68.         }
  69.         if (!$module) {
  70.             $module $this->routingDefaults['bundle'];
  71.         }
  72.         $uri $this->actionRenderer->createControllerReference(
  73.             $module,
  74.             $controller,
  75.             $action,
  76.             $attributes,
  77.             $query
  78.         );
  79.         return $this->actionRenderer->render($uri$options);
  80.     }
  81. }