No Code Attached Yet
avatar crystalenka
crystalenka
18 Jan 2022

Buckle up, folks, this is a weird one.

Steps to reproduce the issue

  1. Create a media custom field. Configuration doesn't matter.
  2. Create another custom field, any type but media. Configuration doesn't matter.
  3. Create a subform with those two fields. Set the "Repeatable" toggle to no. (This is important!)
  4. Open an article with the subform field. Fill out the fields, or don't. It doesn't matter.
  5. Save the article.

Expected result

The media field still displays in the subform, and if any value was added to the media field, it remains.

Actual result

The media field disappears.

Before Save:
Screen Shot 2022-01-18 at 19 29 41

After Save:
Screen Shot 2022-01-18 at 19 29 48

Additionally, if you save the article again, the media field will magically reappear (but empty of any value). This happens regardless of what value (if any) you put in the media field. The only time the media field does NOT reappear is if it is the only field in the subform, which is why I included step 2 above.

System information (as much as possible)

PHP Version: 8.0.14
Joomla! 4.0.6

Additional comments

It's really fun if you save the article so the subform disappears, go back to the subform configuration, add another media field, and go back to edit the article. The media fields switch on every save and are never shown at the same time. 😶

avatar crystalenka crystalenka - open - 18 Jan 2022
avatar joomla-cms-bot joomla-cms-bot - change - 18 Jan 2022
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 18 Jan 2022
avatar brianteeman
brianteeman - comment - 18 Jan 2022

confirmed

avatar crystalenka
crystalenka - comment - 18 Jan 2022

Thanks Brian. Felt like I was going crazy for a while!

avatar brianteeman
brianteeman - comment - 18 Jan 2022

that;s why I quickly posted a confirmation. No idea on the solutions (yet)

avatar richard67
richard67 - comment - 18 Jan 2022

Maybe something for @Fedik ?

avatar richard67
richard67 - comment - 18 Jan 2022

I wish we always had such precise instructions on how to reproduce an issue.

avatar brianteeman
brianteeman - comment - 18 Jan 2022

Must be related to the subform NOT being repeatable as everything works as expected when it is repeatable

avatar crystalenka
crystalenka - comment - 18 Jan 2022

Yup, that's why I included the important note on that step. :)

avatar brianteeman
brianteeman - comment - 18 Jan 2022

About to start filming but I found the problem Maybe someone else will write the fix while I am filming

The record saved in #__filed_values when it is not a repeatable subform

{"field3":{"imagefile":"","alt_text":""},"field4":""}

The record saved in #__filed_values when it is a repeatable subform

{"row0":{"field3":{"imagefile":"","alt_text":""},"field4":""}}

Adding the "row0" container to the field value on the non-repeatable subform and it works

avatar crystalenka
crystalenka - comment - 18 Jan 2022

I think the answer is in plugins/fields/subform/subform.php, possibly rows 174-177 because that's where the plugin tries to account for the non repeatable subform. I have no idea how to debug it but I suspect something is not working as expected there when the subform has a media field?

I don't know, I'm wayyyy out of my depth here.

avatar nikosdion
nikosdion - comment - 18 Jan 2022

I have figured it out. It's a “simple” matter of data format discrepancy. I will submit a PR for 4.1 very soon.

avatar nikosdion
nikosdion - comment - 18 Jan 2022

There you go. It should fairly simple to test.

BTW, neither Brian nor Crystal got the right reason. Since Crystal asked me how did I debug it: The only way to figure out what is going on was to go through a debugger and walk backwards from the subform rendering. After several false starts, I hit Joomla\CMS\Form\Field\SubformField::getInput where I observed that the $forms[0] would include the media subfield in one page load and not the next after saving, then back again after saving again. I then noticed that when we call loadSubFormData in that class $this->value once contained 2 fields (and media field was not shown!) once it contained one field (and the media field WAS shown). How curious! This let me to put a breakpoint in the Joomla\CMS\Form\Field\AccessiblemediaField to see what the actual bleepit bleeping bleep is going on. I saw the array data coming in and falling through to the second branch of the if-block which provided the much necessary a-ha moment.

avatar brianteeman
brianteeman - comment - 18 Jan 2022

yeah I just got back from filming. My main priority was to confirm the bug

avatar richard67 richard67 - change - 18 Jan 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-01-18 23:00:11
Closed_By richard67
avatar richard67 richard67 - close - 18 Jan 2022
avatar richard67
richard67 - comment - 18 Jan 2022

Closing as having a pull request. Please test #36736 . Thanks in advance.

Add a Comment

Login with GitHub to post a comment