Updates Requested bug Small PR-4.4-dev Pending

User tests: Successful: Unsuccessful:

avatar bembelimen
bembelimen
1 Jan 2023

Pull Request for Issue # .

Summary of Changes

For unknown reasons subfoms fieldname ais renamed when generated by custom fields. This leads to the fact, that the field has a new (not unique) fieldname anymore.

Testing Instructions

Generate subforms (several) and try to get their field name like: $form->getField('subform', 'com_fields')->fieldname

Actual result BEFORE applying this Pull Request

only "row"

Expected result AFTER applying this Pull Request

The real name of the field

Additional information

Original PR: #24711

@laoneo @wilsonge @continga probably you see here any issues by removing it?

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar joomla-cms-bot joomla-cms-bot - change - 1 Jan 2023
Category Front End Plugins
avatar bembelimen bembelimen - open - 1 Jan 2023
avatar bembelimen bembelimen - change - 1 Jan 2023
Status New Pending
avatar brianteeman
brianteeman - comment - 1 Jan 2023

@crystalenka tagging you as I am sure you created an issue for this but I cant see it now

avatar bembelimen bembelimen - change - 1 Jan 2023
Labels Added: PR-4.3-dev
avatar crystalenka
crystalenka - comment - 2 Jan 2023

Iirc this will change the way subform fields are called in templates and would majorly break existing templates. I ran into this with the subform issue in the contact display issue I believe

avatar crystalenka
crystalenka - comment - 2 Jan 2023

I just checked and this is the exact same thing I ran into in issue #38737

Check the comments for what I found it affects and why I decided not to change it at that point. (It would be a hard b/c break for templates due to the way JSON is returned.)

avatar Fedik
Fedik - comment - 2 Jan 2023

Thanks @crystalenka for hint about json.

Comment says:

// Override the fieldname attribute of the subform - this is being used to index the rows

I guessing it was made only for array access, like $value['row1'], $value['row2'] ...
And that a ?

Correct would be to use the value as indexed array, before save the value (or before use):

if ($multiple) {
  $value = array_values($value);
}

And that what you always should do when manipulating with subform "rows".
That key newer should be used in PHP, it was made for some fancy manipulation in javascript, in past.

But I not sure that we can fix it in 4.2.x, such changes can introduce a litle break, for anyone who use this key.

avatar bembelimen
bembelimen - comment - 2 Jan 2023

Yes the only "issue" I see is, that when someone access the value directly (the subform itself works) on row0, row1.
As Crystal anyways changed the output, we could add a directly deprecated fallback somehow.

avatar crystalenka
crystalenka - comment - 2 Jan 2023

I did not change the output of the subform plugin, but this PR would

A fallback to avoid breaking layouts would be good because I do think I've seen tutorials (maybe in the magazine?) which instructed people to access the fields directly

avatar brianteeman
brianteeman - comment - 2 Jan 2023

A fallback to avoid breaking layouts would be good because I do think I've seen tutorials (maybe in the magazine?) which instructed people to access the fields directly

and in the docs site

avatar bembelimen
bembelimen - comment - 2 Jan 2023

Do you have a link? Accessing the field shouldn't be a problem, accessing the value is worse

avatar crystalenka
crystalenka - comment - 2 Jan 2023

I know that I personally have accessed the value in some templates and I don't think I came up with it out of nowhere since layout overrides/templates using subforms had to be refactored from Joomla 3 to Joomla 4.

I recall some discussion about it (maybe here in GitHub somewhere? or on Facebook?) about why the fields are indexed by id instead of field name in the JSON, it was an intentional choice at the time that was heavily defended by some contributors but I can't recall by whom or where—sorry.

Unfortunately since this has been how it works for a while I don't think we can change it without providing some kind of fallback, certainly not in 4.x and possibly not in 5 either due to the b/c promise and the fact that this could break some templates or layout overrides pretty substantially. :(

avatar Fedik
Fedik - comment - 2 Jan 2023

In that example used foreach($items as $item):, if your code use the same approach then you in safe.

image

avatar bembelimen
bembelimen - comment - 2 Jan 2023

In that example used foreach($items as $item):, if your code use the same approach then you in safe.

Yes, that's why I'm looking... I see that direct accessing the values can be a problem. That can be overcome by either have the values twice or change the layout itself, so overrides are marked as outdated.

avatar crystalenka
crystalenka - comment - 5 Jan 2023

Overrides would only be marked as outdated if it was an override of the default files though, right? So if someone creates alternative layouts (for example for an article), and assigned that layout to articles in a category, it wouldn't show as outdated. (Correct me if I'm wrong!)

Is it possible to have the values twice and flag it as deprecated, so that people can ensure they're accessing the values correctly before the old way gets removed?

Either way, I don't think that anything should be removed in 4.x....and maybe not in 5.0, either, unless we do a big awareness push as part of the update to 5. :/

avatar brianteeman
brianteeman - comment - 5 Jan 2023

Overrides would only be marked as outdated if it was an override of the default files though, right? So if someone creates alternative layouts (for example for an article), and assigned that layout to articles in a category, it wouldn't show as outdated. (Correct me if I'm wrong!)

you are correct

avatar Fedik
Fedik - comment - 8 Jul 2023

Can you please update your PR.
Also I think this should be remove too:

$cur_field->fieldname = $cur_field->name;
$cur_field->name = 'field' . $cur_field->id;

We should not rename child fields, it may broke a loot of linked JS and etc. As it happen with Showon already.

avatar HLeithner
HLeithner - comment - 30 Sep 2023

This pull request has been automatically rebased to 4.4-dev.

avatar bembelimen bembelimen - change - 2 Jan 2024
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2024-01-02 21:27:32
Closed_By bembelimen
Labels Added: Updates Requested bug Small PR-4.4-dev
Removed: PR-4.3-dev
avatar bembelimen bembelimen - close - 2 Jan 2024

Add a Comment

Login with GitHub to post a comment