2

I need to trigger code when an article is moved from one category to another.

onContentAfterSave works fine for a single article, but what if I move articles via Actions -> Batch? Is there a trigger for that?

1 Answer 1

1

There is an event regarding batch process:

onBeforeBatch(BeforeBatchEvent $event)

and the $event array param is passing the source Table and the type of batch operation, however I have never seen this in use in any plugin.

But what I think is useful event for you to use most probably, without knowing the full purpose, is the

onTableAfterStore(AfterStoreEvent $event)

This event is firing right after the batch operation and the $event param in this case is passing the table and the result

// Extract arguments
/** @var TableInterface $table */
$table  = $event['subject'];
$result = $event['result'];

References to onBeforeBatch event:

This Event class is defined in src/Event/Model/ : https://github.com/joomla/joomla-cms/tree/4.3-dev/libraries/src/Event/Model

According to my fast test in Joomla core taggable plugin, this event is firing when we do a copy type Batch operation on content(articles) items (so at move type operation it does not), so it ignites when we are copying items. I have not checked yet why it is that way.

The event is used in Behaviour/taggable core plugin: https://github.com/joomla/joomla-cms/blob/4.3-dev/plugins/behaviour/taggable/src/Extension/Taggable.php

And the event is property of the Admin Model in Joomla: https://github.com/joomla/joomla-cms/blob/4.3-dev/libraries/src/MVC/Model/AdminModel.php

3
  • 1
    Thanks, @Zollie. Is there documentation for this I can look before placing questions? Or do you know this by digging into Joomla's code? docs.joomla.org/Plugin/Events does not include any reference to onBeforeBatch :( Commented Apr 7, 2023 at 15:51
  • 1
    Yes, i can link you the references: 1. This is event is part (property) of the Admin Model: github.com/joomla/joomla-cms/blob/4.3-dev/libraries/src/MVC/… , so you can check and see it in the code.
    – Zollie
    Commented Apr 7, 2023 at 16:17
  • Maybe i should include these links in my answer too for making it easier for anybody to get references on this event.
    – Zollie
    Commented Apr 7, 2023 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.