Create a user field of type text with "Onle Us In Subform"
Create a user subformfield with the textfield
Create a menu item of type "user profile"
Login in frontend, edit your user and fill the subform field.
Save your profile.
In the profile view the subform field value is missing
The field values should be visible (as works in com_content for subform fields)
Only the subform field label is showing.
Joomla 4.2.2
PHP 8.1
Labels |
Added:
No Code Attached Yet
|
Labels |
Added:
bug
|
Isn't this an ACL issue on the field. I know I looked at this recently on another issue. Will check soon.
No it's an issue with the way the subform field name is passed to the users component:
Field name:string(32) "jform[com_fields][subform-field]"
Field fieldname:string(3) "row"
The fieldname in this case should be subform-field
but it's not for some reason. I'm trying to figure it out.
Part of it is also that the method in com_users to sanitize the value of a field also returns void if the value is an array.
public function value($value)
{
if (is_string($value)) {
$value = trim($value);
}
if (empty($value)) {
return Text::_('COM_USERS_PROFILE_VALUE_NOT_FOUND');
} elseif (!is_array($value)) {
return htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
}
}
but I'm not sure of the original reason for that so I'm not touching it just yet.
I confuised it with another issue
Found it.
https://github.com/joomla/joomla-cms/blob/4.2-dev/plugins/fields/subform/subform.php#L256-L257
// Override the fieldname attribute of the subform - this is being used to index the rows
$parent_field->setAttribute('fieldname', 'row');
Original author for this was @continga but I'm not sure they're active anymore.
Since the user profile template is using the fieldname to find the custom field, it will never find subform fields because we are overriding the parent field.
However, changing the subform plugin to not hardcode it would probably break things? Would that be a breaking change? This is deeper than I expected this issue to go.
I can try to work around it in the template file but it's not a nice solution and might be hard to maintain down the line.
Since the user profile template is using the fieldname to find the custom field, it will never find subform fields because we are overriding the parent field.
is this different to other templates?
Removing that line DOES fix the issue but I don't know where else it might break things.
is this different to other templates?
Yes—most other templates run custom fields through the custom fields renderer. The user profile view has a specific setup so it parses the fields itself.
thats what I remember seeing ;)
So, the change of removing the line I referenced above fixes the issue but would be a BC break for third party code unless I make further changes to the subform.
Originally the subform JSON returns something like the following in the raw value:
"{"row0":{"field1":"1 value test"},"row1":{"field1":"test 2 value test test"}}"
but with my change it returns:
"{"subform-field-name0":{"field1":"1 value test"},"subform-field-name1":{"field1":"test 2 value test test"}}"
Personally I prefer the latter....but the former has been out in the wild long enough that third party templates, overrides, etc would break if we changed it. :(
I'm trying to figure out if I can have the JSON/saved value still be row0 etc without hardcoding the fieldname.
Nope, that would end up affecting all subforms across all components. Forced fieldname correction in user profiles it is. :)
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-09-15 11:05:36 |
Closed_By | ⇒ | richard67 |
Confirmed, taking a look.