Create a simple component with an install script containing a function to addEmailTemplate for this 3rd party component.
`
/**
* Create a new Mail Template
*/
public function addMailTemplate($template_id)
{
$result = MailTemplate::createTemplate(
'com_'.$this->compName.'.'.$template_id,
'COM_'.STRTOUPPER($this->compName).'_EMAILTMPL_'.STRTOUPPER($template_id).'_SUBJECT',
'COM_'.STRTOUPPER($this->compName).'_EMAILTMPL_'.STRTOUPPER($template_id).'_BODY',
array("name","sitename","link_text")
);
Factory::getApplication()->enqueueMessage('Email Template Record Created . . . ');
}
`
A new record to be created in the database with all the relevant data elements.
Missing extension data element and the tags are double arrayed (if that's a thing). So the record doesn't appear in the template listing in the backend. After manually inserting the extension element, trying to open the record from the admin list to edit, fails due to the tags array is within a blank array.
PHP 8.1
Joomla 4.2.6
MySQL 8.0.27
If I update the createTemplate function in MailTemplate to the following all works as expected.
`
/**
* Insert a new mail template into the system
*
* @param string $key Mail template key
* @param string $extension Extension
* @param string $subject A default subject (normally a translatable string)
* @param string $body A default body (normally a translatable string)
* @param array $tags Associative array of tags to replace
* @param string $htmlbody A default htmlbody (normally a translatable string)
*
* @return boolean True on success, false on failure
*
* @since 4.0.0
*/
public static function createTemplate($key, $extension, $subject, $body, $tags, $htmlbody = '')
{
$db = Factory::getDbo();
$template = new \stdClass();
$template->template_id = $key;
$template->extension = $extension;
$template->language = '';
$template->subject = $subject;
$template->body = $body;
$template->htmlbody = $htmlbody;
$template->attachments = '';
$params = new \stdClass();
$params->tags = $tags;
$template->params = json_encode($params);
return $db->insertObject('#__mail_templates', $template);
}
`
Labels |
Added:
No Code Attached Yet
|
Labels |
Added:
bug
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-01-02 07:19:11 |
Closed_By | ⇒ | richard67 |
That one even worse than previous :)
There a PR for fixing it #37898 but it have a potential backward compatibility issue.