src/Eccube/Twig/Extension/EccubeBlockExtension.php line 46

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Twig\Extension;
  13. use Twig\Environment;
  14. use Twig\Extension\AbstractExtension;
  15. use Twig\TwigFunction;
  16. class EccubeBlockExtension extends AbstractExtension
  17. {
  18.     protected $twig;
  19.     protected $blockTemplates;
  20.     public function __construct(Environment $twig, array $blockTemplates)
  21.     {
  22.         $this->twig $twig;
  23.         $this->blockTemplates $blockTemplates;
  24.     }
  25.     public function getFunctions()
  26.     {
  27.         return [
  28.             new TwigFunction('eccube_block_*', function ($context$name, array $parameters = []) {
  29.                 if (!empty($parameters)) {
  30.                     $context array_merge($context$parameters);
  31.                 }
  32.                 $files $this->blockTemplates;
  33.                 foreach ($files as $file) {
  34.                     $template $this->twig->load($file);
  35.                     if ($template->hasBlock($name$context)) {
  36.                         return $template->renderBlock($name$context);
  37.                     }
  38.                 }
  39.                 @trigger_error($name.' block is not found'E_USER_WARNING);
  40.             }, ['needs_context' => true'pre_escape' => 'html''is_safe' => ['html']]),
  41.         ];
  42.     }
  43. }