Create a plugin with an event "onContentPrepareForm" like this
public function onContentPrepareForm($form, $data) {
if (count($data)) {
// get article params
$attribs = $data->get('attribs');
}
}
Edit an article and try to change its category. The fatal error appears that the get does not exists.
$data shall be the associated data for the form.
$data is empty
Joomla! 3.7.0
On article loading, $data returns a JObect
when switching the category, the $data in the article returns a simple Array
this is not correct because I'm still in the article and I need to edit the attribs
I have used this to avoid the error, but the problem is in the fact that $data shall be a JObject and not an Array
if (method_exists($data,'get')) {
$attribs = $data->get('attribs');
} else if (isset($data['attribs'])) {
$attribs = $data['attribs'];
}
That was my misunderstanding, yes you are right $data should remain JObject
You need to figure out what type of data you get, take a look at this: https://github.com/joomla/joomla-cms/blob/staging/plugins/system/fields/fields.php#L194
I'm already checking the context, I'm in 'com_content.article' in both cases
this problem was not there before the 3.7
Check it with 3.6.5 it is the same you get an empty array or a jObject
I'm having an similair issue, but without a plugin as above.
Simply when creating an article and then change the category.
Please see: https://forum.joomla.org/viewtopic.php?f=706&t=950583
I have no further info then the Error itself.
@rdeutz : no matter in which version this has been introduced, it just does not work as expected :)
oh no, it works as expected, if you check the profile plugin you will find:
/**
* Adds additional fields to the user editing form
*
* @param JForm $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @return boolean
*
* @since 1.6
*/
$data has a type of mixed. No question that this is not a brillant idea to have different types for a parameter but thats's how it is.
Closing not a bug
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-05-17 11:44:49 |
Closed_By | ⇒ | rdeutz |
ok I agree. Then we don't investigate more to change this ?
We just close it ... it's a shame
You are free to make a pull request or open a ticket with a suggestion how to change it, this ticket gives the impression we have to fix a bug.
ok Robert I understand :)
Then it is not a bug, but something we could improve (my 2 cents).
I will then investigate.
Thanks !
Try this: