BackendTemplate.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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\Config\ScopeConfigInterface;
  8. /**
  9. * Adminhtml email template model
  10. *
  11. * @api
  12. *
  13. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  14. * @since 100.0.2
  15. */
  16. class BackendTemplate extends Template
  17. {
  18. /**
  19. * @var \Magento\Config\Model\Config\Structure
  20. */
  21. private $structure;
  22. /**
  23. * @param \Magento\Framework\Model\Context $context
  24. * @param \Magento\Framework\View\DesignInterface $design
  25. * @param \Magento\Framework\Registry $registry
  26. * @param \Magento\Store\Model\App\Emulation $appEmulation
  27. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  28. * @param \Magento\Framework\View\Asset\Repository $assetRepo
  29. * @param \Magento\Framework\Filesystem $filesystem
  30. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  31. * @param \Magento\Email\Model\Template\Config $emailConfig
  32. * @param \Magento\Email\Model\TemplateFactory $templateFactory
  33. * @param \Magento\Framework\Filter\FilterManager $filterManager
  34. * @param \Magento\Framework\UrlInterface $urlModel
  35. * @param \Magento\Email\Model\Template\FilterFactory $filterFactory
  36. * @param \Magento\Config\Model\Config\Structure $structure
  37. * @param array $data
  38. * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
  39. *
  40. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  41. */
  42. public function __construct(
  43. \Magento\Framework\Model\Context $context,
  44. \Magento\Framework\View\DesignInterface $design,
  45. \Magento\Framework\Registry $registry,
  46. \Magento\Store\Model\App\Emulation $appEmulation,
  47. \Magento\Store\Model\StoreManagerInterface $storeManager,
  48. \Magento\Framework\View\Asset\Repository $assetRepo,
  49. \Magento\Framework\Filesystem $filesystem,
  50. \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
  51. \Magento\Email\Model\Template\Config $emailConfig,
  52. \Magento\Email\Model\TemplateFactory $templateFactory,
  53. \Magento\Framework\Filter\FilterManager $filterManager,
  54. \Magento\Framework\UrlInterface $urlModel,
  55. \Magento\Email\Model\Template\FilterFactory $filterFactory,
  56. \Magento\Config\Model\Config\Structure $structure,
  57. array $data = [],
  58. \Magento\Framework\Serialize\Serializer\Json $serializer = null
  59. ) {
  60. $this->structure = $structure;
  61. parent::__construct(
  62. $context,
  63. $design,
  64. $registry,
  65. $appEmulation,
  66. $storeManager,
  67. $assetRepo,
  68. $filesystem,
  69. $scopeConfig,
  70. $emailConfig,
  71. $templateFactory,
  72. $filterManager,
  73. $urlModel,
  74. $filterFactory,
  75. $data,
  76. $serializer
  77. );
  78. }
  79. /**
  80. * Collect all system config paths where current template is currently used
  81. *
  82. * @return array
  83. */
  84. public function getSystemConfigPathsWhereCurrentlyUsed()
  85. {
  86. $templateId = $this->getId();
  87. if (!$templateId) {
  88. return [];
  89. }
  90. $templatePaths = $this->structure->getFieldPathsByAttribute(
  91. 'source_model',
  92. \Magento\Config\Model\Config\Source\Email\Template::class
  93. );
  94. if (!count($templatePaths)) {
  95. return [];
  96. }
  97. $configData = $this->_getResource()->getSystemConfigByPathsAndTemplateId($templatePaths, $templateId);
  98. foreach ($templatePaths as $path) {
  99. if ($this->scopeConfig->getValue($path, ScopeConfigInterface::SCOPE_TYPE_DEFAULT) == $templateId) {
  100. foreach ($configData as $data) {
  101. if ($data['path'] == $path) {
  102. continue 2; // don't add final fallback value if it was found in stored config
  103. }
  104. }
  105. $configData[] = [
  106. 'scope' => ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
  107. 'path' => $path
  108. ];
  109. }
  110. }
  111. return $configData;
  112. }
  113. }