1
我正在开发一个带onContentAfterSave事件的Joomla插件,用于在保存新文章后发送电子邮件。Joomla:onContentAfterSave未触发文章
当我保存新的菜单项或新的类别时,触发事件。 但不适用于新文章。
Joomla! 3.7.5
public function onContentAfterSave($context, $article, $isNew){
$link = JRoute::_(ContentHelperRoute::getArticleRoute( $article->id, $article->catid));
$mailer = JFactory::getMailer();
$config = JFactory::getConfig();
$sender = array(
$config->get('mailfrom'),
$config->get('fromname')
);
$mailer->setSender($sender);
$user = JFactory::getUser();
$recipient = $user->email;
$recipient = array($recipient);
$mailer->addRecipient($recipient);
$body = '<p>Bonjour</p>'
.'Un nouveau <a href="'.$link.'">article</a> a été ajouté.';
$mailer->isHtml(true);
$mailer->Encoding = 'base64';
$mailer->setSubject('Nouveau article - BBN Times');
$mailer->setBody($body);
$send = $mailer->Send();
if ($send !== true) {
echo 'Error sending email: ';
} else {
echo 'Mail sent';
}
return true;
}
我的插件适用于所有类型(菜单,类别...),但不适用于文章类型。其实我使用这个条件 if($ isNew and in_array($ context,array('com_content.article','com_content.form'))) – emwww