![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/fooman/pdfcore-m2/src/Model/ |
<?php /** * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz) * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Fooman\PdfCore\Model; use Magento\Email\Model\Template\Config; use Magento\Email\Model\Template\FilterFactory; use Magento\Email\Model\TemplateFactory; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\RequestInterface; use Magento\Framework\Filesystem; use Magento\Framework\Filter\FilterManager; use Magento\Framework\Model\Context; use Magento\Framework\Registry; use Magento\Framework\UrlInterface; use Magento\Framework\View\Asset\Repository; use Magento\Framework\View\DesignInterface; use Magento\Framework\View\LayoutFactory; use Magento\Store\Model\App\Emulation; use Magento\Store\Model\StoreManagerInterface; class Template extends \Magento\Email\Model\Template { /** * @var RequestInterface */ protected $request; /** * @var LayoutFactory */ protected $layoutFactory; /** * @var \Magento\Framework\App\State */ protected $appState; public function __construct( Context $context, DesignInterface $design, Registry $registry, Emulation $appEmulation, StoreManagerInterface $storeManager, Repository $assetRepo, Filesystem $filesystem, ScopeConfigInterface $scopeConfig, Config $emailConfig, TemplateFactory $templateFactory, FilterManager $filterManager, UrlInterface $urlModel, FilterFactory $filterFactory, RequestInterface $request, LayoutFactory $layoutFactory, array $data = [] ) { $this->request = $request; $this->layoutFactory = $layoutFactory; $this->appState = $context->getAppState(); parent::__construct( $context, $design, $registry, $appEmulation, $storeManager, $assetRepo, $filesystem, $scopeConfig, $emailConfig, $templateFactory, $filterManager, $urlModel, $filterFactory, $data ); } public function processTemplate() { $this->forceLocaleInAdmin(); $isDesignApplied = $this->applyDesignConfig(); $this->setIsLegacy(true); $html = $this->getProcessedTemplate($this->_getVars()); if ($isDesignApplied) { $this->cancelDesignConfig(); } return $html; } public function processLayout($layoutHandle) { $this->forceLocaleInAdmin(); $isDesignApplied = $this->applyDesignConfig(); if ($this->appState->getAreaCode() !== \Magento\Framework\App\Area::AREA_FRONTEND) { $html = $this->appState->emulateAreaCode( \Magento\Framework\App\Area::AREA_FRONTEND, [$this, 'getProcessedLayout'], ['layoutHandle' => $layoutHandle, 'variables' => $this->_getVars()] ); } else { $html = $this->getProcessedLayout($layoutHandle, $this->_getVars()); } if ($isDesignApplied) { $this->cancelDesignConfig(); } return $html; } public function getProcessedLayout($layoutHandle, $variables = []) { $layout = $this->layoutFactory->create(['cacheable' => false]); $layout->getUpdate()->load([$layoutHandle]); $layout->generateXml(); $layout->generateElements(); $rootBlock = false; foreach ($layout->getAllBlocks() as $block) { if (!$block->getParentBlock() && !$rootBlock) { $rootBlock = true; $layout->addOutputElement($block->getNameInLayout()); } foreach ($variables as $variable => $value) { $block->setData($variable, $value); } } $output = $layout->getOutput(); $layout->__destruct(); return $output; } private function forceLocaleInAdmin() { $storeId = $this->getDesignConfig()->getStore(); $locale = $this->scopeConfig->getValue( \Magento\Directory\Helper\Data::XML_PATH_DEFAULT_LOCALE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId ); $params = $this->request->getParams(); $params['locale'] = $locale; $this->request->setParams($params); } }