templateFactory = $templateFactory; $this->storeManager = $storeManager; $this->templateResource = $templateResource; $this->helper = $helper; $this->request = $request; parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); } /** * @return \Magento\Framework\App\Config\Value */ public function beforeDelete() { $dotTemplate = $this->templateFactory->create(); $this->helper->deleteConfigData( $dotTemplate->templateConfigMapping[$this->getField()], $this->getScope(), $this->getScopeId() ); return parent::beforeDelete(); } /** * @return \Magento\Framework\App\Config\Value */ public function beforeSave() { if (! $this->isValueChanged()) { return parent::beforeSave(); } $dotTemplate = $this->templateFactory->create(); $templateConfigId = $this->getField(); $scope = $this->getScope(); $scopeId = $this->getScopeId(); //email template mapped if ($this->getValue()) { $templateConfigPath = $dotTemplate->templateConfigMapping[$templateConfigId]; $template = $dotTemplate->saveTemplateWithConfigPath( $templateConfigId, $this->getValue(), $scope, $scopeId ); //save successful created new email template with the default config value for template. if ($template) { $this->helper->saveConfigData( $templateConfigPath, $template->getId(), $scope, $scopeId ); } } else { //remove the config for core email template $this->helper->deleteConfigData( $dotTemplate->templateConfigMapping[$templateConfigId], $scope, $scopeId ); //remove the config for dotmailer template $this->helper->deleteConfigData( $dotTemplate->templateConfigIdToDotmailerConfigPath[$templateConfigId], $scope, $scopeId ); } return parent::beforeSave(); } }