AbstractTemplate.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Email\Model;
  7. use Magento\Framework\App\Filesystem\DirectoryList;
  8. use Magento\Framework\App\TemplateTypesInterface;
  9. use Magento\Framework\DataObject;
  10. use Magento\Framework\Exception\LocalizedException;
  11. use Magento\Framework\Model\AbstractModel;
  12. use Magento\Store\Model\Information as StoreInformation;
  13. use Magento\Store\Model\ScopeInterface;
  14. use Magento\Store\Model\Store;
  15. /**
  16. * Template model class
  17. *
  18. * @author Magento Core Team <core@magentocommerce.com>
  19. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  20. * @SuppressWarnings(PHPMD.TooManyFields)
  21. * @api
  22. * @since 100.0.2
  23. */
  24. abstract class AbstractTemplate extends AbstractModel implements TemplateTypesInterface
  25. {
  26. /**
  27. * Default design area for emulation
  28. */
  29. const DEFAULT_DESIGN_AREA = 'frontend';
  30. /**
  31. * Default path to email logo
  32. */
  33. const DEFAULT_LOGO_FILE_ID = 'Magento_Email::logo_email.png';
  34. /**
  35. * Email logo url
  36. */
  37. const XML_PATH_DESIGN_EMAIL_LOGO = 'design/email/logo';
  38. /**
  39. * Email logo alt text
  40. */
  41. const XML_PATH_DESIGN_EMAIL_LOGO_ALT = 'design/email/logo_alt';
  42. /**
  43. * Email logo width
  44. */
  45. const XML_PATH_DESIGN_EMAIL_LOGO_WIDTH = 'design/email/logo_width';
  46. /**
  47. * Email logo height
  48. */
  49. const XML_PATH_DESIGN_EMAIL_LOGO_HEIGHT = 'design/email/logo_height';
  50. /**
  51. * Configuration of design package for template
  52. *
  53. * @var DataObject
  54. */
  55. private $designConfig;
  56. /**
  57. * Whether template is child of another template
  58. *
  59. * @var bool
  60. */
  61. private $isChildTemplate = false;
  62. /**
  63. * Email template filter
  64. *
  65. * @var \Magento\Email\Model\Template\Filter
  66. */
  67. private $templateFilter;
  68. /**
  69. * Configuration of emulated design package.
  70. *
  71. * @var DataObject|boolean
  72. */
  73. private $emulatedDesignConfig = false;
  74. /**
  75. * Package area
  76. *
  77. * @var string
  78. */
  79. private $area;
  80. /**
  81. * Store id
  82. *
  83. * @var int
  84. */
  85. private $store;
  86. /**
  87. * Tracks whether design has been applied within the context of this template model.
  88. *
  89. * Important as there are multiple entry points for the applyDesignConfig method.
  90. *
  91. * @var bool
  92. */
  93. private $hasDesignBeenApplied = false;
  94. /**
  95. * @var \Magento\Email\Model\TemplateFactory
  96. */
  97. protected $templateFactory = null;
  98. /**
  99. * Design package instance
  100. *
  101. * @var \Magento\Framework\View\DesignInterface
  102. */
  103. protected $design = null;
  104. /**
  105. * @var \Magento\Store\Model\App\Emulation
  106. */
  107. protected $appEmulation;
  108. /**
  109. * @var \Magento\Store\Model\StoreManagerInterface
  110. */
  111. protected $storeManager;
  112. /**
  113. * Asset service
  114. *
  115. * @var \Magento\Framework\View\Asset\Repository
  116. */
  117. protected $assetRepo;
  118. /**
  119. * @var \Magento\Framework\Filesystem
  120. */
  121. protected $filesystem;
  122. /**
  123. * Scope config
  124. *
  125. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  126. */
  127. protected $scopeConfig;
  128. /**
  129. * @var \Magento\Email\Model\Template\Config
  130. */
  131. protected $emailConfig;
  132. /**
  133. * @var \Magento\Framework\Filter\FilterManager
  134. */
  135. protected $filterManager;
  136. /**
  137. * @var \Magento\Framework\UrlInterface
  138. */
  139. private $urlModel;
  140. /**
  141. * @param \Magento\Framework\Model\Context $context
  142. * @param \Magento\Framework\View\DesignInterface $design
  143. * @param \Magento\Framework\Registry $registry
  144. * @param \Magento\Store\Model\App\Emulation $appEmulation
  145. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  146. * @param \Magento\Framework\View\Asset\Repository $assetRepo
  147. * @param \Magento\Framework\Filesystem $filesystem
  148. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  149. * @param \Magento\Email\Model\Template\Config $emailConfig
  150. * @param \Magento\Email\Model\TemplateFactory $templateFactory
  151. * @param \Magento\Framework\Filter\FilterManager $filterManager
  152. * @param \Magento\Framework\UrlInterface $urlModel
  153. * @param array $data
  154. *
  155. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  156. */
  157. public function __construct(
  158. \Magento\Framework\Model\Context $context,
  159. \Magento\Framework\View\DesignInterface $design,
  160. \Magento\Framework\Registry $registry,
  161. \Magento\Store\Model\App\Emulation $appEmulation,
  162. \Magento\Store\Model\StoreManagerInterface $storeManager,
  163. \Magento\Framework\View\Asset\Repository $assetRepo,
  164. \Magento\Framework\Filesystem $filesystem,
  165. \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
  166. \Magento\Email\Model\Template\Config $emailConfig,
  167. \Magento\Email\Model\TemplateFactory $templateFactory,
  168. \Magento\Framework\Filter\FilterManager $filterManager,
  169. \Magento\Framework\UrlInterface $urlModel,
  170. array $data = []
  171. ) {
  172. $this->design = $design;
  173. $this->area = isset($data['area']) ? $data['area'] : null;
  174. $this->store = isset($data['store']) ? $data['store'] : null;
  175. $this->appEmulation = $appEmulation;
  176. $this->storeManager = $storeManager;
  177. $this->assetRepo = $assetRepo;
  178. $this->filesystem = $filesystem;
  179. $this->scopeConfig = $scopeConfig;
  180. $this->emailConfig = $emailConfig;
  181. $this->templateFactory = $templateFactory;
  182. $this->filterManager = $filterManager;
  183. $this->urlModel = $urlModel;
  184. parent::__construct($context, $registry, null, null, $data);
  185. }
  186. /**
  187. * Get contents of the included template for template directive
  188. *
  189. * @param string $configPath
  190. * @param array $variables
  191. * @return string
  192. */
  193. public function getTemplateContent($configPath, array $variables)
  194. {
  195. $template = $this->getTemplateInstance();
  196. // Ensure child templates have the same area/store context as parent
  197. $template->setDesignConfig($this->getDesignConfig()->toArray())
  198. ->loadByConfigPath($configPath, $variables)
  199. ->setTemplateType($this->getType())
  200. ->setIsChildTemplate(true);
  201. // automatically strip tags if in a plain-text parent
  202. if ($this->isPlain()) {
  203. $templateText = $this->filterManager->stripTags($template->getTemplateText());
  204. $template->setTemplateText(trim($templateText));
  205. }
  206. $processedTemplate = $template->getProcessedTemplate($variables);
  207. if ($this->isPlain()) {
  208. $processedTemplate = trim($processedTemplate);
  209. }
  210. return $processedTemplate;
  211. }
  212. /**
  213. * Return a new instance of the template object. Used by the template directive.
  214. *
  215. * @return \Magento\Email\Model\AbstractTemplate
  216. */
  217. protected function getTemplateInstance()
  218. {
  219. return $this->templateFactory->create();
  220. }
  221. /**
  222. * Load template from database when overridden in configuration or load default from relevant file system location.
  223. *
  224. * @param string $configPath
  225. * @return \Magento\Email\Model\AbstractTemplate
  226. */
  227. public function loadByConfigPath($configPath)
  228. {
  229. $store = $this->getDesignConfig()->getStore();
  230. $templateId = $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORE, $store);
  231. if (is_numeric($templateId)) {
  232. $this->load($templateId);
  233. } else {
  234. $this->loadDefault($templateId);
  235. }
  236. return $this;
  237. }
  238. /**
  239. * Load default email template
  240. *
  241. * @param string $templateId
  242. * @return $this
  243. */
  244. public function loadDefault($templateId)
  245. {
  246. $designParams = $this->getDesignParams();
  247. $templateFile = $this->emailConfig->getTemplateFilename($templateId, $designParams);
  248. $templateType = $this->emailConfig->getTemplateType($templateId);
  249. $templateTypeCode = $templateType == 'html' ? self::TYPE_HTML : self::TYPE_TEXT;
  250. $this->setTemplateType($templateTypeCode);
  251. $rootDirectory = $this->filesystem->getDirectoryRead(DirectoryList::ROOT);
  252. $templateText = $rootDirectory->readFile($rootDirectory->getRelativePath($templateFile));
  253. /**
  254. * trim copyright message
  255. */
  256. if (preg_match('/^<!--[\w\W]+?-->/m', $templateText, $matches) && strpos($matches[0], 'Copyright') !== false) {
  257. $templateText = str_replace($matches[0], '', $templateText);
  258. }
  259. if (preg_match('/<!--@subject\s*(.*?)\s*@-->/u', $templateText, $matches)) {
  260. $this->setTemplateSubject($matches[1]);
  261. $templateText = str_replace($matches[0], '', $templateText);
  262. }
  263. if (preg_match('/<!--@vars\s*((?:.)*?)\s*@-->/us', $templateText, $matches)) {
  264. $this->setData('orig_template_variables', str_replace("\n", '', $matches[1]));
  265. $templateText = str_replace($matches[0], '', $templateText);
  266. }
  267. if (preg_match('/<!--@styles\s*(.*?)\s*@-->/s', $templateText, $matches)) {
  268. $this->setTemplateStyles($matches[1]);
  269. $templateText = str_replace($matches[0], '', $templateText);
  270. }
  271. // Remove comment lines and extra spaces
  272. $templateText = trim(preg_replace('#\{\*.*\*\}#suU', '', $templateText));
  273. $this->setTemplateText($templateText);
  274. $this->setId($templateId);
  275. return $this;
  276. }
  277. /**
  278. * Process email template code
  279. *
  280. * @param array $variables
  281. * @return string
  282. * @throws \Magento\Framework\Exception\MailException
  283. */
  284. public function getProcessedTemplate(array $variables = [])
  285. {
  286. $processor = $this->getTemplateFilter()
  287. ->setUseSessionInUrl(false)
  288. ->setPlainTemplateMode($this->isPlain())
  289. ->setIsChildTemplate($this->isChildTemplate())
  290. ->setTemplateProcessor([$this, 'getTemplateContent']);
  291. $variables['this'] = $this;
  292. $isDesignApplied = $this->applyDesignConfig();
  293. // Set design params so that CSS will be loaded from the proper theme
  294. $processor->setDesignParams($this->getDesignParams());
  295. if (isset($variables['subscriber'])) {
  296. $storeId = $variables['subscriber']->getStoreId();
  297. } else {
  298. $storeId = $this->getDesignConfig()->getStore();
  299. }
  300. $processor->setStoreId($storeId);
  301. // Populate the variables array with store, store info, logo, etc. variables
  302. $variables = $this->addEmailVariables($variables, $storeId);
  303. $processor->setVariables($variables);
  304. try {
  305. $result = $processor->filter($this->getTemplateText());
  306. } catch (\Exception $e) {
  307. $this->cancelDesignConfig();
  308. throw new \LogicException(__($e->getMessage()), $e->getCode(), $e);
  309. }
  310. if ($isDesignApplied) {
  311. $this->cancelDesignConfig();
  312. }
  313. return $result;
  314. }
  315. /**
  316. * Get default email logo image
  317. *
  318. * @return string
  319. */
  320. public function getDefaultEmailLogo()
  321. {
  322. $designParams = $this->getDesignParams();
  323. return $this->assetRepo->getUrlWithParams(
  324. self::DEFAULT_LOGO_FILE_ID,
  325. $designParams
  326. );
  327. }
  328. /**
  329. * Return logo URL for emails. Take logo from theme if custom logo is undefined
  330. *
  331. * @param Store|int|string $store
  332. * @return string
  333. */
  334. protected function getLogoUrl($store)
  335. {
  336. $store = $this->storeManager->getStore($store);
  337. $fileName = $this->scopeConfig->getValue(
  338. self::XML_PATH_DESIGN_EMAIL_LOGO,
  339. ScopeInterface::SCOPE_STORE,
  340. $store
  341. );
  342. if ($fileName) {
  343. $uploadDir = \Magento\Email\Model\Design\Backend\Logo::UPLOAD_DIR;
  344. $mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
  345. if ($mediaDirectory->isFile($uploadDir . '/' . $fileName)) {
  346. return $this->storeManager->getStore()->getBaseUrl(
  347. \Magento\Framework\UrlInterface::URL_TYPE_MEDIA
  348. ) . $uploadDir . '/' . $fileName;
  349. }
  350. }
  351. return $this->getDefaultEmailLogo();
  352. }
  353. /**
  354. * Return logo alt for emails
  355. *
  356. * @param Store|int|string $store
  357. * @return string
  358. */
  359. protected function getLogoAlt($store)
  360. {
  361. $store = $this->storeManager->getStore($store);
  362. $alt = $this->scopeConfig->getValue(
  363. self::XML_PATH_DESIGN_EMAIL_LOGO_ALT,
  364. ScopeInterface::SCOPE_STORE,
  365. $store
  366. );
  367. if ($alt) {
  368. return $alt;
  369. }
  370. return $store->getFrontendName();
  371. }
  372. /**
  373. * Add variables that are used by transactional and newsletter emails
  374. *
  375. * @param array $variables
  376. * @param null|string|bool|int|Store $storeId
  377. * @return mixed
  378. *
  379. * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  380. * @SuppressWarnings(PHPMD.NPathComplexity)
  381. */
  382. protected function addEmailVariables($variables, $storeId)
  383. {
  384. $store = $this->storeManager->getStore($storeId);
  385. if (!isset($variables['store'])) {
  386. $variables['store'] = $store;
  387. }
  388. if (!isset($variables['logo_url'])) {
  389. $variables['logo_url'] = $this->getLogoUrl($storeId);
  390. }
  391. if (!isset($variables['logo_alt'])) {
  392. $variables['logo_alt'] = $this->getLogoAlt($storeId);
  393. }
  394. if (!isset($variables['logo_width'])) {
  395. $variables['logo_width'] = $this->scopeConfig->getValue(
  396. self::XML_PATH_DESIGN_EMAIL_LOGO_WIDTH,
  397. ScopeInterface::SCOPE_STORE,
  398. $store
  399. );
  400. }
  401. if (!isset($variables['logo_height'])) {
  402. $variables['logo_height'] = $this->scopeConfig->getValue(
  403. self::XML_PATH_DESIGN_EMAIL_LOGO_HEIGHT,
  404. ScopeInterface::SCOPE_STORE,
  405. $store
  406. );
  407. }
  408. if (!isset($variables['store_phone'])) {
  409. $variables['store_phone'] = $this->scopeConfig->getValue(
  410. StoreInformation::XML_PATH_STORE_INFO_PHONE,
  411. ScopeInterface::SCOPE_STORE,
  412. $store
  413. );
  414. }
  415. if (!isset($variables['store_hours'])) {
  416. $variables['store_hours'] = $this->scopeConfig->getValue(
  417. StoreInformation::XML_PATH_STORE_INFO_HOURS,
  418. ScopeInterface::SCOPE_STORE,
  419. $store
  420. );
  421. }
  422. if (!isset($variables['store_email'])) {
  423. $variables['store_email'] = $this->scopeConfig->getValue(
  424. 'trans_email/ident_support/email',
  425. ScopeInterface::SCOPE_STORE,
  426. $store
  427. );
  428. }
  429. // If template is text mode, don't include styles
  430. if (!$this->isPlain() && !isset($variables['template_styles'])) {
  431. $variables['template_styles'] = $this->getTemplateStyles();
  432. }
  433. return $variables;
  434. }
  435. /**
  436. * Apply design config so that emails are processed within the context of the appropriate area/store/theme.
  437. * Can be called multiple times without issue.
  438. *
  439. * @return bool
  440. */
  441. protected function applyDesignConfig()
  442. {
  443. // Only run app emulation if this is the parent template and emulation isn't already running.
  444. // Otherwise child will run inside parent emulation.
  445. if ($this->isChildTemplate() || $this->hasDesignBeenApplied) {
  446. return false;
  447. }
  448. $this->hasDesignBeenApplied = true;
  449. $designConfig = $this->getDesignConfig();
  450. $storeId = $designConfig->getStore();
  451. $area = $designConfig->getArea();
  452. if ($storeId !== null) {
  453. // Force emulation in case email is being sent from same store so that theme will be loaded. Helpful
  454. // for situations where emails may be sent from bootstrap files that load frontend store, but not theme
  455. $this->appEmulation->startEnvironmentEmulation($storeId, $area, true);
  456. }
  457. return true;
  458. }
  459. /**
  460. * Revert design settings to previous
  461. *
  462. * @return $this
  463. */
  464. protected function cancelDesignConfig()
  465. {
  466. $this->appEmulation->stopEnvironmentEmulation();
  467. $this->hasDesignBeenApplied = false;
  468. return $this;
  469. }
  470. /**
  471. * Store the area associated with a template so that it will be returned by getDesignConfig and getDesignParams
  472. *
  473. * @param string $templateId
  474. * @return $this
  475. */
  476. public function setForcedArea($templateId)
  477. {
  478. if ($this->area === null) {
  479. $this->area = $this->emailConfig->getTemplateArea($templateId);
  480. }
  481. return $this;
  482. }
  483. /**
  484. * Manually set a theme that will be used by getParams
  485. *
  486. * Used to force the loading of an email template from a specific theme
  487. *
  488. * @param string $templateId
  489. * @param string $theme
  490. * @return $this
  491. */
  492. public function setForcedTheme($templateId, $theme)
  493. {
  494. $area = $this->emailConfig->getTemplateArea($templateId);
  495. $this->design->setDesignTheme($theme, $area);
  496. return $this;
  497. }
  498. /**
  499. * Returns the design params for the template being processed
  500. *
  501. * @return array
  502. */
  503. public function getDesignParams()
  504. {
  505. return [
  506. // Retrieve area from getDesignConfig, rather than the getDesignTheme->getArea(), as the latter doesn't
  507. // return the emulated area
  508. 'area' => $this->getDesignConfig()->getArea(),
  509. 'theme' => $this->design->getDesignTheme()->getCode(),
  510. 'themeModel' => $this->design->getDesignTheme(),
  511. 'locale' => $this->design->getLocale(),
  512. ];
  513. }
  514. /**
  515. * Get design configuration data
  516. *
  517. * @return DataObject
  518. */
  519. public function getDesignConfig()
  520. {
  521. if ($this->designConfig === null) {
  522. if ($this->area === null) {
  523. $this->area = $this->design->getArea();
  524. }
  525. if ($this->store === null) {
  526. $this->store = $this->storeManager->getStore()->getId();
  527. }
  528. $this->designConfig = new DataObject(
  529. ['area' => $this->area, 'store' => $this->store]
  530. );
  531. }
  532. return $this->designConfig;
  533. }
  534. /**
  535. * Initialize design information for template processing
  536. *
  537. * @param array $config
  538. * @return $this
  539. * @throws LocalizedException
  540. */
  541. public function setDesignConfig(array $config)
  542. {
  543. if (!isset($config['area']) || !isset($config['store'])) {
  544. throw new LocalizedException(
  545. __('The design config needs an area and a store. Verify that both are set and try again.')
  546. );
  547. }
  548. $this->getDesignConfig()->setData($config);
  549. return $this;
  550. }
  551. /**
  552. * Check whether template is child of another template
  553. *
  554. * @return bool
  555. */
  556. public function isChildTemplate()
  557. {
  558. return $this->isChildTemplate;
  559. }
  560. /**
  561. * Set whether template is child of another template
  562. *
  563. * @param bool $isChildTemplate
  564. * @return $this
  565. */
  566. public function setIsChildTemplate($isChildTemplate)
  567. {
  568. $this->isChildTemplate = (bool) $isChildTemplate;
  569. return $this;
  570. }
  571. /**
  572. * Declare template processing filter
  573. *
  574. * @param \Magento\Email\Model\Template\Filter $filter
  575. * @return $this
  576. */
  577. public function setTemplateFilter(Template\Filter $filter)
  578. {
  579. $this->templateFilter = $filter;
  580. return $this;
  581. }
  582. /**
  583. * Get filter object for template processing
  584. *
  585. * @return \Magento\Email\Model\Template\Filter
  586. */
  587. public function getTemplateFilter()
  588. {
  589. if (empty($this->templateFilter)) {
  590. $this->templateFilter = $this->getFilterFactory()->create();
  591. $this->templateFilter->setUseAbsoluteLinks($this->getUseAbsoluteLinks())
  592. ->setStoreId($this->getDesignConfig()->getStore())
  593. ->setUrlModel($this->urlModel);
  594. }
  595. return $this->templateFilter;
  596. }
  597. /**
  598. * Save current design config and replace with design config from specified store
  599. * Event is not dispatched.
  600. *
  601. * @param null|bool|int|string $storeId
  602. * @param string $area
  603. * @return void
  604. */
  605. public function emulateDesign($storeId, $area = self::DEFAULT_DESIGN_AREA)
  606. {
  607. if ($storeId !== null && $storeId !== false) {
  608. // save current design settings
  609. $this->emulatedDesignConfig = clone $this->getDesignConfig();
  610. if ($this->getDesignConfig()->getStore() != $storeId
  611. || $this->getDesignConfig()->getArea() != $area
  612. ) {
  613. $this->setDesignConfig(['area' => $area, 'store' => $storeId]);
  614. $this->applyDesignConfig();
  615. }
  616. } else {
  617. $this->emulatedDesignConfig = false;
  618. }
  619. }
  620. /**
  621. * Revert to last design config, used before emulation
  622. *
  623. * @return void
  624. */
  625. public function revertDesign()
  626. {
  627. if ($this->emulatedDesignConfig) {
  628. $this->setDesignConfig($this->emulatedDesignConfig->getData());
  629. $this->cancelDesignConfig();
  630. $this->emulatedDesignConfig = false;
  631. }
  632. }
  633. /**
  634. * Return true if template type eq text
  635. *
  636. * @return boolean
  637. */
  638. public function isPlain()
  639. {
  640. return $this->getType() == self::TYPE_TEXT;
  641. }
  642. /**
  643. * Getter for filter factory that is specific to the type of template being processed
  644. *
  645. * @return mixed
  646. */
  647. abstract protected function getFilterFactory();
  648. /**
  649. * Getter for template type
  650. *
  651. * @return int|string
  652. */
  653. abstract public function getType();
  654. /**
  655. * Generate URL for the specified store.
  656. *
  657. * @param Store $store
  658. * @param string $route
  659. * @param array $params
  660. * @return string
  661. */
  662. public function getUrl(Store $store, $route = '', $params = [])
  663. {
  664. $url = $this->urlModel->setScope($store);
  665. if ($this->storeManager->getStore()->getId() != $store->getId()) {
  666. $params['_scope_to_url'] = true;
  667. }
  668. return $url->getUrl($route, $params);
  669. }
  670. }