Testing custom component on Joomla 3.7 beta3 and found an issue with System - Fields plugin.
In my component I allow to perform onContentPrepare
event on item that has fields
property. I am passing correct context like com_component.entity
. But System - Fields plugin simply resets fields
property and sets CMS fields instead of my fields.
public function onContentPrepare($context, $item)
{
$parts = FieldsHelper::extract($context, $item);
if (!$parts)
{
return;
}
$fields = FieldsHelper::getFields($parts[0] . '.' . $parts[1], $item, true);
// Adding the fields to the object
$item->fields = array();
foreach ($fields as $key => $field)
{
$item->fields[$field->id] = $field;
}
return;
}
The question is - am I the only one who uses fields
as a name for the property or we could expect more unpredictable behavior for custom extensions?
Labels |
Added:
?
|
May be we can check for fields
property and if it is set then assign fields to another property, like jfields
or something. I do not think this will break anything in the CMS.
The question is - am I the only one who uses fields as a name for the property or we could expect more unpredictable behavior for custom extensions?
You are not the only one, i have same problem, i have to save / restore / rename properties ...
A more unique name would be nice
We need something like this:
// Adding the fields to the object
$property = isset($item->fields) ? 'jfields' : 'fields';
$item->$property = array();
I wouldn't do a conditional. We either use fields
or another name. Best is to use another name if we know it will clash.
In #13353 I use com_fields
as the fieldset name (instead of params). I guess we could use that here as well as the property name. It would be clear for anyone what it is and it is highly unlikely that this property already exists in another extension.
// Adding the fields to the object
$property = isset($item->fields) ? 'jfields' : 'fields';
$item->$property = array();
The above is problematic, having 2 names means
that all code using custom fields will need to check if 'jfields' property is set and then use it instead of 'fields'
Can 'fields' just be rename to 'jfields' ? or 'jcfields' ?
Also i think i remember a couple of other components using $item->fields property (i need to search and confirm)
Can 'fields' just be renamed to 'jfields' ? or 'jcfields' ?
Of course this could be the best option.jcfields
is a winner, I think :)
jcfields
sounds for me also ok.
Something wrong with com_fields
? Just to keep it consistent with my other proposal if possible.
If it is not possible then I'm fine with jcfields
as well. I could also use that in my other PR to be consistent.
For me it looks awkward to have a property with the name com_fields.
For me it looks awkward to have a property with the name com_fields.
Agree :)
i like jfields more
For me it looks awkward to have a property with the name com_fields.
Maybe, but it's crystal clear and doesn't need a comment what it is
It's been merged now.
It doesn't need to be the same name, but it may help.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-03-11 16:13:20 |
Closed_By | ⇒ | b2z |
What would be the alternative to make the fields available on the entity? This is something which comes from dpfields, there was the name more unique as it was unlikely that another extension will have a property with the name dpfields.