No Code Attached Yet bug
avatar angieradtke
angieradtke
14 Sep 2020

Just playing around with the subfom custom field and the template overrides,
I noticed that the $field->name is not its name but its id.
Is that the expected behavior or a bug?

{ ["myfield"]=> object(stdClass)#1211 (34) { ["id"]=> int(6) ["title"]=> string(4) "myfield" ["name"]=> string(6) "field6"

Bye Angie

avatar angieradtke angieradtke - open - 14 Sep 2020
avatar joomla-cms-bot joomla-cms-bot - change - 14 Sep 2020
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 14 Sep 2020
avatar SharkyKZ
SharkyKZ - comment - 15 Sep 2020

Looks intentional:

/**
* Set the name of the sub field to its id so that the values in the database are being saved
* based on the id of the sub fields, not on their name. Actually we do not need the name of
* the sub fields to render them, but just to make sure we have the name when we need it, we
* store it as `fieldname`.
*/
$cur_field->fieldname = $cur_field->name;
$cur_field->name = 'field' . $cur_field->id;

Use $field->fieldname to get what you need.

avatar jiweigert
jiweigert - comment - 15 Sep 2020

Ok, it's implemented like this, so yes intentional by the look of it.
But from developer view, it is misleading and unexpected to access a value through $field->name
and get the id as result back, instead of the requested name (as the $field->name suggests).


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30638.

avatar AndySDH
AndySDH - comment - 16 Sep 2020

Yeah it's implemented like this because it needs to be stored in the database based on the ID.

The name of a field can be changed. The ID cannot. If it was stored based on name, all data would be lost if the name changed.

avatar jiweigert
jiweigert - comment - 16 Sep 2020

The question here is not to save something or change the the unique key from fieldid to fieldname.

The question (I think) is, that the naming of the getter (function) $field->name is incorrect and irritating, when you get the field-id as result and not the field-name you expect by using that getter (function).

avatar angieradtke
angieradtke - comment - 16 Sep 2020

Yeah it's implemented like this because it needs to be stored in the database based on the ID.

uiuiui that sounds as it is
hastily cobbled together ?

avatar crystalenka
crystalenka - comment - 27 Jul 2021

I came across this today and agree it doesn't make sense as a template developer. It's also a departure for how subforms work in Joomla 3, making it harder to port template overrides when everyone updates.

The name of a field can be changed. The ID cannot. If it was stored based on name, all data would be lost if the name changed.

No one is saying it should not be stored by ID, but not allowing us to access the data by name is unintuitive and frustrating, and makes it harder to write readable (and therefore easily maintainable) code. If the ID must be included in the JSON, then it should also include the name as a column so those of us who need it can use it.

avatar AndySDH
AndySDH - comment - 27 Jul 2021

I think the best solution is to fix this and actually have the name of the field in $field->name.

But still making sure to save the value in the database by the "field25" method (eg. where ID is 25). But not sure if that's possible (are the two things even correlated? the object and how the db stores them?)

If not, even just using the ID in the database would work, so eg. even simply "25".

avatar Hackwar Hackwar - change - 20 Feb 2023
Labels Added: No Code Attached Yet bug
Removed: ?
avatar Hackwar Hackwar - labeled - 20 Feb 2023

Add a Comment

Login with GitHub to post a comment