* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ declare(strict_types=1); namespace PrestaShopBundle\Twig\Extension; use PrestaShopBundle\Controller\Admin\MultistoreController; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; /** * Class MultistoreComponentsExtension provides helper function to get the multistore components' html in a template */ class MultistoreComponentsExtension extends AbstractExtension { /** * @var MultistoreController */ private $multistoreController; /** * MultistoreHeaderExtension constructor. * * @param MultistoreController $multistoreController */ public function __construct(MultistoreController $multistoreController) { $this->multistoreController = $multistoreController; } /** * {@inheritdoc} */ public function getFunctions(): array { return [ new TwigFunction('multistoreHeader', [$this, 'getMultistoreHeader'], ['is_safe' => ['html']]), new TwigFunction('multistoreProductHeader', [$this, 'getMultistoreProductHeader'], ['is_safe' => ['html']]), ]; } /** * @param bool $lockedToAllShopContext * * @return string */ public function getMultistoreHeader(bool $lockedToAllShopContext = false): string { return $this->multistoreController->header($lockedToAllShopContext)->getContent(); } /** * @param int $productId * * @return string */ public function getMultistoreProductHeader(int $productId): string { return $this->multistoreController->productHeader($productId)->getContent(); } }