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
Labels |
Added:
?
|
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).
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.
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).
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 ?
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.
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".
Labels |
Added:
No Code Attached Yet
bug
Removed: ? |
Looks intentional:
joomla-cms/plugins/fields/subfields/subfields.php
Lines 423 to 430 in 4574ff9
Use
$field->fieldname
to get what you need.