?
avatar b2z
b2z
9 Mar 2017

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?

avatar b2z b2z - open - 9 Mar 2017
avatar joomla-cms-bot joomla-cms-bot - change - 9 Mar 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 9 Mar 2017
avatar laoneo
laoneo - comment - 9 Mar 2017

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.

avatar b2z
b2z - comment - 9 Mar 2017

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.

avatar ggppdk
ggppdk - comment - 9 Mar 2017

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

avatar b2z
b2z - comment - 10 Mar 2017

We need something like this:

// Adding the fields to the object
$property = isset($item->fields) ? 'jfields' : 'fields';

$item->$property = array();
avatar Bakual
Bakual - comment - 10 Mar 2017

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.

avatar ggppdk
ggppdk - comment - 10 Mar 2017
// 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' ?

avatar ggppdk
ggppdk - comment - 10 Mar 2017

Also i think i remember a couple of other components using $item->fields property (i need to search and confirm)

avatar b2z
b2z - comment - 10 Mar 2017

Can 'fields' just be renamed to 'jfields' ? or 'jcfields' ?
Of course this could be the best option. jcfields is a winner, I think :)

avatar laoneo
laoneo - comment - 10 Mar 2017

jcfieldssounds for me also ok.

avatar Bakual
Bakual - comment - 10 Mar 2017

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.

avatar laoneo
laoneo - comment - 10 Mar 2017

For me it looks awkward to have a property with the name com_fields.

avatar b2z
b2z - comment - 10 Mar 2017

For me it looks awkward to have a property with the name com_fields.

Agree :)

avatar coolcat-creations
coolcat-creations - comment - 10 Mar 2017

i like jfields more ? :)

avatar Bakual
Bakual - comment - 10 Mar 2017

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.

avatar laoneo
laoneo - comment - 11 Mar 2017

Please have a look on pr #14493. It renames the field to jcfields. Can we close this one?

avatar b2z b2z - change - 11 Mar 2017
Status New Closed
Closed_Date 0000-00-00 00:00:00 2017-03-11 16:13:20
Closed_By b2z
avatar b2z b2z - close - 11 Mar 2017
avatar b2z
b2z - comment - 15 Mar 2017

Hello! Please help to test #14493

Add a Comment

Login with GitHub to post a comment