User tests: Successful: 2 brianteeman, crystalenka Unsuccessful: 0
Pull Request for Issue #36734 .
Addresses the data format discrepancy between what Joomla\CMS\Form\Field\AccessiblemediaField
expects and what a non-repeatable subform custom field provides.
Per issue #36734:
The media field disappears every other save. Any images you set in the field is ignored; the field appears in its default (empty) state when it reappears.
The media field still displays in the subform, and if any value was added to the media field, it remains.
None
This problem happens because Joomla is playing fast and loose with data types.
The subform custom field stores its value as a JSON document. This includes the values of each and every subfield contained in it. It is always decoded to an associative array, including the subfields' data.
The Media custom field's value is meant to be either an object or a string (which can be a JSON-serialised object or a legacy image file path without alt text). That's how the setup() method of the AccessiblemediaField class expects its values.
When combining the two you create the observed problem.
When you load a custom field it decodes the JSON value into an associative array. This means that the internal data of the Media custom field is also decoded as an array. Since the AccessiblemediaField does not accept an array it considers the data invalid, setup() returns false and the field is removed from the form. Therefore its data is removed when you save the content (e.g. article) again. The next page load has no value for this field stored so the field falls back to its default empty state due to the fall-through of the setup() method's opening if-block and displays, albeit empty.
The dead simple solution is to check if the incoming value is an array and type cast it to an object. This satisfies the if-block's conditions and the field displays correctly.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
I have tested this item
Thank you!!!
Status | Pending | ⇒ | Ready to Commit |
RTC
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-01-20 03:00:07 |
Closed_By | ⇒ | bembelimen | |
Labels |
Added:
?
?
|
Thx
I have tested this item✅ successfully on 76f60f7
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/36736.