- md5
- 54f750eb1aa0e6a75bf629d4bef77e74
- sha1
- 6e9d7bdbf6b7272cb7c13e413ab44b2e9da6731e
- sha256
- bfc5c3e75b794f67e7f36293044c9e926c773798dec508743fe6de5e150230db
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
<?php
/**
* @package Joomla.Administrator
* @subpackage com_mails
*
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Mails\Administrator\View\Template;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Mails\Administrator\Helper\MailsHelper;
use Joomla\Component\Mails\Administrator\Model\TemplateModel;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* View to edit a mail template.
*
* @since 4.0.0
*/
class HtmlView extends BaseHtmlView
{
/**
* The Form object
*
* @var \Joomla\CMS\Form\Form
*/
protected $form;
/**
* The active item
*
* @var \stdClass
*/
protected $item;
/**
* The model state
*
* @var object
*/
protected $state;
/**
* The template data
*
* @var array
*/
protected $templateData;
/**
* Master data for the mail template
*
* @var \stdClass
*/
protected $master;
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*
* @since 4.0.0
*/
public function display($tpl = null)
{
/** @var TemplateModel $model */
$model = $this->getModel();
$model->setUseExceptions(true);
$this->state = $model->getState();
$this->item = $model->getItem();
$this->master = $model->getMaster();
$this->form = $model->getForm();
[$extension, $template_id] = explode('.', $this->item->template_id, 2);
$fields = ['subject', 'body', 'htmlbody'];
$this->templateData = [];
MailsHelper::loadTranslationFiles($extension, $this->item->language);
$this->master->subject = Text::_($this->master->subject);
$this->master->body = Text::_($this->master->body);
if ($this->master->htmlbody) {
$this->master->htmlbody = Text::_($this->master->htmlbody);
} else {
$this->master->htmlbody = nl2br($this->master->body, false);
}
$this->templateData = [
'subject' => $this->master->subject,
'body' => $this->master->body,
'htmlbody' => $this->master->htmlbody,
];
foreach ($fields as $field) {
if (\is_null($this->item->$field) || $this->item->$field == '') {
$this->item->$field = $this->master->$field;
$this->form->setValue($field, null, $this->item->$field);
}
}
// Add form control fields
$this->form
->addControlField('task', '')
->addControlField('return', Factory::getApplication()->getInput()->get('return', '', 'BASE64'));
$this->addToolbar();
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 4.0.0
*/
protected function addToolbar()
{
Factory::getApplication()->getInput()->set('hidemainmenu', true);
$toolbar = $this->getDocument()->getToolbar();
ToolbarHelper::title(
Text::_('COM_MAILS_PAGE_EDIT_MAIL'),
'pencil-2 article-add'
);
$toolbar->apply('template.apply');
$toolbar->divider();
$toolbar->save('template.save');
$toolbar->divider();
$toolbar->cancel('template.cancel', 'JTOOLBAR_CLOSE');
$toolbar->divider();
$toolbar->help('Mail_Template:_Edit');
}
}
The same content is in 17 releases, Joomla 6.0.0-beta2 to 6.1.0-alpha2. See them all, or every version of this file.