Triggering onContentChangeState from another plugin?

40 views
Skip to first unread message

Ronny Buelund

unread,
Sep 23, 2024, 1:49:27 PM9/23/24
to Joomla! General Development
I use an extension to automatically unpublish articles after 30 days. I need this extension(plugin) to trigger the onContentChangeState event so that my selfmade plugin that acts on this trigger will send out an email. 
But how do I trigger the onContentChangeState event from inside this other plugin ?

Stephen

unread,
Sep 23, 2024, 6:41:35 PM9/23/24
to Joomla! General Development
Try below:


public function onContentPrepare($context, &$article, &$params, $page = 0) { $days = $this->params->get('days', 30); $publishDate = new DateTime($article->publish_up); $currentDate = new DateTime(); if ($publishDate->diff($currentDate)->days >= $days) { $article->state = 0; } }

Ronny Buelund

unread,
Sep 25, 2024, 2:48:09 PM9/25/24
to Joomla! General Development
I think you misunderstand. I have now created a task plugin that unpublishes articles in a certain category when the publish_up date is more than 30 days old. I need this task plugin to also trigger the onContentChangeState  event, which my mail plugin acts on. How would I do that ?

Ronny Buelund

unread,
Sep 26, 2024, 3:29:24 PM9/26/24
to Joomla! General Development
Ok - I found the solution. To trigger the  onContentChangeState event  from inside another plugin, on an article with for example id=4:

use Joomla\CMS\Factory;
use Joomla\CMS\CMSObject;
use Joomla\CMS\Plugin\PluginHelper;

$article[0] = 4;
PluginHelper::importPlugin('content');
$app = Factory::getApplication();
$test = $app->triggerEvent('onContentChangeState', array('com_content.article', &$article, &$params, 0));
Reply all
Reply to author
Forward
0 new messages