Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Template Class Reference
Inheritance diagram for Template:
AbstractTemplate TemplateInterface AbstractModel TemplateTypesInterface TemplateTypesInterface DataObject BackendTemplate

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\View\DesignInterface $design, \Magento\Framework\Registry $registry, \Magento\Store\Model\App\Emulation $appEmulation, StoreManagerInterface $storeManager, \Magento\Framework\View\Asset\Repository $assetRepo, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Email\Model\Template\Config $emailConfig, \Magento\Email\Model\TemplateFactory $templateFactory, \Magento\Framework\Filter\FilterManager $filterManager, \Magento\Framework\UrlInterface $urlModel, \Magento\Email\Model\Template\FilterFactory $filterFactory, array $data=[], \Magento\Framework\Serialize\Serializer\Json $serializer=null)
 
 getId ()
 
 setId ($value)
 
 isValidForSend ()
 
 getType ()
 
 getSendingException ()
 
 getProcessedTemplateSubject (array $variables)
 
 addBcc ($bcc)
 
 setReturnPath ($email)
 
 setReplyTo ($email)
 
 getVariablesOptionArray ($withGroup=false)
 
 beforeSave ()
 
 processTemplate ()
 
 getSubject ()
 
 setVars (array $vars)
 
 setOptions (array $options)
 
- Public Member Functions inherited from AbstractTemplate
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\View\DesignInterface $design, \Magento\Framework\Registry $registry, \Magento\Store\Model\App\Emulation $appEmulation, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\View\Asset\Repository $assetRepo, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Email\Model\Template\Config $emailConfig, \Magento\Email\Model\TemplateFactory $templateFactory, \Magento\Framework\Filter\FilterManager $filterManager, \Magento\Framework\UrlInterface $urlModel, array $data=[])
 
 getTemplateContent ($configPath, array $variables)
 
 loadByConfigPath ($configPath)
 
 loadDefault ($templateId)
 
 getProcessedTemplate (array $variables=[])
 
 getDefaultEmailLogo ()
 
 setForcedArea ($templateId)
 
 setForcedTheme ($templateId, $theme)
 
 getDesignParams ()
 
 getDesignConfig ()
 
 setDesignConfig (array $config)
 
 isChildTemplate ()
 
 setIsChildTemplate ($isChildTemplate)
 
 setTemplateFilter (Template\Filter $filter)
 
 getTemplateFilter ()
 
 emulateDesign ($storeId, $area=self::DEFAULT_DESIGN_AREA)
 
 revertDesign ()
 
 isPlain ()
 
 getType ()
 
 getUrl (Store $store, $route='', $params=[])
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Data Fields

const XML_PATH_SENDING_SET_RETURN_PATH = 'system/smtp/set_return_path'
 
const XML_PATH_SENDING_RETURN_PATH_EMAIL = 'system/smtp/return_path_email'
 
const XML_PATH_SYSTEM_SMTP_DISABLE = 'system/smtp/disable'
 
- Data Fields inherited from AbstractTemplate
const DEFAULT_DESIGN_AREA = 'frontend'
 
const DEFAULT_LOGO_FILE_ID = 'Magento_Email::logo_email.png'
 
const XML_PATH_DESIGN_EMAIL_LOGO = 'design/email/logo'
 
const XML_PATH_DESIGN_EMAIL_LOGO_ALT = 'design/email/logo_alt'
 
const XML_PATH_DESIGN_EMAIL_LOGO_WIDTH = 'design/email/logo_width'
 
const XML_PATH_DESIGN_EMAIL_LOGO_HEIGHT = 'design/email/logo_height'
 
- Data Fields inherited from TemplateTypesInterface
const TYPE_TEXT = 1
 
const TYPE_HTML = 2
 

Protected Member Functions

 _construct ()
 
 _parseVariablesString ($variablesString)
 
 getFilterFactory ()
 
 _getVars ()
 
- Protected Member Functions inherited from AbstractTemplate
 getTemplateInstance ()
 
 getLogoUrl ($store)
 
 getLogoAlt ($store)
 
 addEmailVariables ($variables, $storeId)
 
 applyDesignConfig ()
 
 cancelDesignConfig ()
 
 getFilterFactory ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_bcc = []
 
 $_returnPath = ''
 
 $_replyTo = ''
 
 $_vars = []
 
 $_sendingException = null
 
- Protected Attributes inherited from AbstractTemplate
 $templateFactory = null
 
 $design = null
 
 $appEmulation
 
 $storeManager
 
 $assetRepo
 
 $filesystem
 
 $scopeConfig
 
 $emailConfig
 
 $filterManager
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Template model

@method string getTemplateCode() @method \Magento\Email\Model\Template setTemplateCode(string $value) @method string getTemplateText() @method \Magento\Email\Model\Template setTemplateText(string $value) @method string getTemplateStyles() @method \Magento\Email\Model\Template setTemplateStyles(string $value) @method int getTemplateType() @method \Magento\Email\Model\Template setTemplateType(int $value) @method string getTemplateSubject() @method \Magento\Email\Model\Template setTemplateSubject(string $value) @method string getTemplateSenderName() @method \Magento\Email\Model\Template setTemplateSenderName(string $value) @method string getTemplateSenderEmail() @method \Magento\Email\Model\Template setTemplateSenderEmail(string $value) @method string getAddedAt() @method \Magento\Email\Model\Template setAddedAt(string $value) @method string getModifiedAt() @method \Magento\Email\Model\Template setModifiedAt(string $value) @method string getOrigTemplateCode() @method \Magento\Email\Model\Template setOrigTemplateCode(string $value) @method string getOrigTemplateVariables() @method \Magento\Email\Model\Template setOrigTemplateVariables(string $value)

@api

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 41 of file Template.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\View\DesignInterface  $design,
\Magento\Framework\Registry  $registry,
\Magento\Store\Model\App\Emulation  $appEmulation,
StoreManagerInterface  $storeManager,
\Magento\Framework\View\Asset\Repository  $assetRepo,
\Magento\Framework\Filesystem  $filesystem,
\Magento\Framework\App\Config\ScopeConfigInterface  $scopeConfig,
\Magento\Email\Model\Template\Config  $emailConfig,
\Magento\Email\Model\TemplateFactory  $templateFactory,
\Magento\Framework\Filter\FilterManager  $filterManager,
\Magento\Framework\UrlInterface  $urlModel,
\Magento\Email\Model\Template\FilterFactory  $filterFactory,
array  $data = [],
\Magento\Framework\Serialize\Serializer\Json  $serializer = null 
)

Template constructor.

Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\View\DesignInterface$design
\Magento\Framework\Registry$registry
\Magento\Store\Model\App\Emulation$appEmulation
StoreManagerInterface$storeManager
\Magento\Framework\View\Asset\Repository$assetRepo
\Magento\Framework\Filesystem$filesystem
\Magento\Framework\App\Config\ScopeConfigInterface$scopeConfig
Template\Config$emailConfig
TemplateFactory$templateFactory
\Magento\Framework\Filter\FilterManager$filterManager
\Magento\Framework\UrlInterface$urlModel
Template\FilterFactory$filterFactory
array$data
\Magento\Framework\Serialize\Serializer\Json | null$serializer
Exceptions

Definition at line 128 of file Template.php.

144  {
145  $this->filterFactory = $filterFactory;
146  $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
147  ->get(\Magento\Framework\Serialize\Serializer\Json::class);
148  parent::__construct(
149  $context,
150  $design,
151  $registry,
154  $assetRepo,
155  $filesystem,
156  $scopeConfig,
157  $emailConfig,
160  $urlModel,
161  $data
162  );
163  }

Member Function Documentation

◆ _construct()

_construct ( )
protected

Initialize email template model

Returns
void

Definition at line 170 of file Template.php.

171  {
172  $this->_init(\Magento\Email\Model\ResourceModel\Template::class);
173  }

◆ _getVars()

_getVars ( )
protected

Retrieve template variables

Returns
array

Definition at line 433 of file Template.php.

434  {
435  return $this->_vars;
436  }

◆ _parseVariablesString()

_parseVariablesString (   $variablesString)
protected

Parse variables string into array of variables

Parameters
string$variablesString
Returns
array

Definition at line 304 of file Template.php.

305  {
306  $variables = [];
307  if ($variablesString && is_string($variablesString)) {
308  $variablesString = str_replace("\n", '', $variablesString);
309  $variables = $this->serializer->unserialize($variablesString);
310  }
311  return $variables;
312  }

◆ addBcc()

addBcc (   $bcc)

Add email BCC

Parameters
string | array$bcc
Returns
$this @codeCoverageIgnore

Definition at line 266 of file Template.php.

267  {
268  $this->_bcc[] = $bcc;
269  return $this;
270  }

◆ beforeSave()

beforeSave ( )

Validate email template code

Exceptions

Definition at line 341 of file Template.php.

342  {
343  $code = $this->getTemplateCode();
344  if (empty($code)) {
345  throw new \Magento\Framework\Exception\MailException(__('Please enter a template name.'));
346  }
347  if ($this->_getResource()->checkCodeUsage($this)) {
348  throw new \Magento\Framework\Exception\MailException(__('Duplicate Of Template Name'));
349  }
350  parent::beforeSave();
351  return $this;
352  }
__()
Definition: __.php:13
$code
Definition: info.phtml:12

◆ getFilterFactory()

getFilterFactory ( )
protected
Returns
\Magento\Email\Model\Template\FilterFactory

Definition at line 423 of file Template.php.

424  {
425  return $this->filterFactory;
426  }

◆ getId()

getId ( )

Return template id

Returns
int|null

Definition at line 180 of file Template.php.

181  {
182  return $this->getTemplateId();
183  }

◆ getProcessedTemplateSubject()

getProcessedTemplateSubject ( array  $variables)

Process email subject

Parameters
array$variables
Returns
string
Exceptions

Definition at line 239 of file Template.php.

240  {
241  $processor = $this->getTemplateFilter();
242 
243  $variables['this'] = $this;
244 
245  $processor->setVariables($variables);
246 
247  $this->applyDesignConfig();
248  $storeId = $this->getDesignConfig()->getStore();
249  try {
250  $processedResult = $processor->setStoreId($storeId)->filter(__($this->getTemplateSubject()));
251  } catch (\Exception $e) {
252  $this->cancelDesignConfig();
253  throw new \Magento\Framework\Exception\MailException(__($e->getMessage()), $e);
254  }
255  $this->cancelDesignConfig();
256  return $processedResult;
257  }
$processor
Definition: 404.php:10
__()
Definition: __.php:13

◆ getSendingException()

getSendingException ( )

Get exception, generated during send() method

Returns
\Exception|null @codeCoverageIgnore

Definition at line 227 of file Template.php.

228  {
230  }

◆ getSubject()

getSubject ( )

Get processed subject

Returns
string

Implements TemplateInterface.

Definition at line 392 of file Template.php.

393  {
394  return $this->getProcessedTemplateSubject($this->_getVars());
395  }
getProcessedTemplateSubject(array $variables)
Definition: Template.php:239

◆ getType()

getType ( )

Getter for template type

Returns
int

Implements TemplateTypesInterface.

Definition at line 211 of file Template.php.

212  {
213  $templateType = $this->getTemplateType();
214  if (null === $templateType && $this->getId()) {
215  $templateType = $this->emailConfig->getTemplateType($this->getId());
217  }
218  return $templateType !== null ? $templateType : self::TYPE_HTML;
219  }
$templateType
Definition: list.phtml:37

◆ getVariablesOptionArray()

getVariablesOptionArray (   $withGroup = false)

Retrieve option array of variables

Parameters
boolean$withGroupif true wrap variable options in group
Returns
array

Definition at line 320 of file Template.php.

321  {
322  $optionArray = [];
323  $variables = $this->_parseVariablesString($this->getData('orig_template_variables'));
324  if ($variables) {
325  foreach ($variables as $value => $label) {
326  $optionArray[] = ['value' => '{{' . $value . '}}', 'label' => __('%1', $label)];
327  }
328  if ($withGroup) {
329  $optionArray = ['label' => __('Template Variables'), 'value' => $optionArray];
330  }
331  }
332  return $optionArray;
333  }
getData($key='', $index=null)
Definition: DataObject.php:119
__()
Definition: __.php:13
$label
Definition: details.phtml:21
$value
Definition: gender.phtml:16
_parseVariablesString($variablesString)
Definition: Template.php:304

◆ isValidForSend()

isValidForSend ( )

Return true if this template can be used for sending queue as main template

Returns
bool

Definition at line 201 of file Template.php.

202  {
203  return $this->getSenderName() && $this->getSenderEmail() && $this->getTemplateSubject();
204  }

◆ processTemplate()

processTemplate ( )

Get processed template

Returns
string
Exceptions

Implements TemplateInterface.

Definition at line 360 of file Template.php.

361  {
362  // Support theme fallback for email templates
363  $isDesignApplied = $this->applyDesignConfig();
364 
365  $templateId = $this->getId();
366  if (is_numeric($templateId)) {
367  $this->load($templateId);
368  } else {
369  $this->loadDefault($templateId);
370  }
371 
372  if (!$this->getId()) {
373  throw new \Magento\Framework\Exception\MailException(
374  __('Invalid transactional email code: %1', $templateId)
375  );
376  }
377 
378  $this->setUseAbsoluteLinks(true);
379  $text = $this->getProcessedTemplate($this->_getVars());
380 
381  if ($isDesignApplied) {
382  $this->cancelDesignConfig();
383  }
384  return $text;
385  }
__()
Definition: __.php:13
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43
$templateId
Definition: queue.php:15

◆ setId()

setId (   $value)

Set id of template

Parameters
int$value
Returns
$this

Definition at line 191 of file Template.php.

192  {
193  return $this->setTemplateId($value);
194  }
$value
Definition: gender.phtml:16

◆ setOptions()

setOptions ( array  $options)

Set template options

Parameters
array$options
Returns
$this

Implements TemplateInterface.

Definition at line 415 of file Template.php.

416  {
417  return $this->setDesignConfig($options);
418  }

◆ setReplyTo()

setReplyTo (   $email)

Add Reply-To header

Parameters
string$email
Returns
$this @codeCoverageIgnore

Definition at line 292 of file Template.php.

293  {
294  $this->_replyTo = $email;
295  return $this;
296  }
$email
Definition: details.phtml:13

◆ setReturnPath()

setReturnPath (   $email)

Set Return Path

Parameters
string$email
Returns
$this @codeCoverageIgnore

Definition at line 279 of file Template.php.

280  {
281  $this->_returnPath = $email;
282  return $this;
283  }
$email
Definition: details.phtml:13

◆ setVars()

setVars ( array  $vars)

Set template variables

Parameters
array$vars
Returns
$this

Implements TemplateInterface.

Definition at line 403 of file Template.php.

404  {
405  $this->_vars = $vars;
406  return $this;
407  }

Field Documentation

◆ $_bcc

$_bcc = []
protected

Definition at line 68 of file Template.php.

◆ $_replyTo

$_replyTo = ''
protected

Definition at line 82 of file Template.php.

◆ $_returnPath

$_returnPath = ''
protected

Definition at line 75 of file Template.php.

◆ $_sendingException

$_sendingException = null
protected

Definition at line 92 of file Template.php.

◆ $_vars

$_vars = []
protected

Definition at line 87 of file Template.php.

◆ XML_PATH_SENDING_RETURN_PATH_EMAIL

const XML_PATH_SENDING_RETURN_PATH_EMAIL = 'system/smtp/return_path_email'

Configuration path for custom Return-Path email

Deprecated:
See also
\Magento\Email\Model\Transport::XML_PATH_SENDING_RETURN_PATH_EMAIL

Definition at line 55 of file Template.php.

◆ XML_PATH_SENDING_SET_RETURN_PATH

const XML_PATH_SENDING_SET_RETURN_PATH = 'system/smtp/set_return_path'

Configuration path to source of Return-Path and whether it should be set at all

Deprecated:
See also
\Magento\Email\Model\Transport::XML_PATH_SENDING_SET_RETURN_PATH

Definition at line 48 of file Template.php.

◆ XML_PATH_SYSTEM_SMTP_DISABLE

const XML_PATH_SYSTEM_SMTP_DISABLE = 'system/smtp/disable'

Config path to mail sending setting that shows if email communications are disabled

Deprecated:

Definition at line 61 of file Template.php.


The documentation for this class was generated from the following file: