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