0

I created a plugin to send published articles data to external service

class plgSystemVacancypub extends JPlugin { public function onContentAfterSave($context, $article, $isNew) { // Get custom fields values $customFieldnames = FieldsHelper::getFields('com_content.article', $article->get('id'), true); $customFieldIds = array_map(create_function('$o', 'return $o->id;'), $customFieldnames); $fmodel = JModelLegacy::getInstance('Field', 'FieldsModel', array('ignore_request' => true)); $customFieldValues= $fmodel->getFieldValues($customFieldIds , $article->get('id')); // Send to external function } } 

But in my article I have some custom fields. First saving the article the $customFieldValues variable is empty. And when I click to Save article once again, custom fields are exists. As I know the custom fields saves after article saving. How can I replace the subsequence of executing "save the custom fields" and my plugin? I want to see custom fields values on first publishing of article.

2
  • I'm not sure of the answer, and I don't fully understand the question. But perhaps you can watch this video. It might be that you are hooking onto the plugin system at the wrong time. youtube.com/watch?v=_agXP5DHm_g Commented Feb 7, 2024 at 11:35
  • If simple, I need first save custom fields values of article, then execute my plugin (in which I use custom fields values). Commented Feb 7, 2024 at 17:18

2 Answers 2

0

Well, I didn't found the solution to my problem. But I found another way - correcting the fields plugin (plugins/fields/fields.php), which saves custom fields after article saved. Now I have access to values of all custom fields of first time saving article in onContentAfterSave function.

0

That event has an undocumented aditional argument $data which holds the saved data!

public function onContentAfterSave($context, $item, $isNew, $data = []){ } 

Just in case, set its default to an empty array.

If you check your custom field in the $data it will be there after the event is fired.

For example, for a standard field like the tags, just get them like this:

$thetagssaved = $data['tags']; 

For a custom field named "myfield", get it like this:

$myfieldvalue = $data['com_fields']['myfield']; 

If you have doubts on what you need to get, output the $data into your log:

error_log(print_r($data, true)); 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.