Bug #91236
openNumeric array keys are not merged correctly in YAML import
0%
Description
If in a YAML file another one is included by imports, numeric array keys are reset, if they are already described elsewhere in the current file or another import.
This functionality is important for the Form Framework to be able to split its own finishers into several YAML files. There is a way around this in ext:form (simply do not import the values separately, but define them centered somewhere else), but this does not allow a clean separation.
Example:
If you want to insert a value into file A.yaml under TYPO3.CMS.Form.prototypes.standard.formElementsDefinition.Form.formEditor.editors.900.selectOptions, this works without any problems. If you now add another value to file B.yaml, the values do not appear at the end under 900.selectOptions, but under 0.selectOptions and 1.selectOptions.
This only happens when one or both of these files are imported into a YAML file. If the files are loaded independently via TypoScript, it works without problems.
Example A.yaml:
TYPO3:
CMS:
Form:
test:
20:
a: b
Example B.yaml:
TYPO3:
CMS:
Form:
test:
20:
e: f
21:
c: d
My FormSetup.yaml:
imports:
- { resource: "./A.yaml" }
- { resource: "./B.yaml" }
This results in the following result:
TYPO3:
CMS:
Form:
test:
0:
e: f
1:
c: d
2:
a: b
Which it should be:
TYPO3:
CMS:
Form:
test:
20:
a: b
e: f
21:
c: d
Updated by Jigal van Hemert about 4 years ago
In TypoScript numerical keys are kept as they are. This is documented to allow items to be inserted between existing items.
Combining yaml files uses logic for numerical keys that is similar to the PHP function array_merge. This also explains why the numerical keys are renumbered.
The hard part in this regard is that lists in yaml usually don't use any keys, but when converted to PHP arrays numerical keys are automatically introduced (PHP arrays must have a numerical or string key). The behaviour when importing yaml files is correct from the point of view of a basic yaml list.
The Forms configuration uses numerical keys like TypoScript does.
After the data is converted to PHP arrays it's impossible to see is it was automatically numbered or not.
Updated by Stephan Jorek over 3 years ago
- Related to Bug #94729: Method ArrayUtility::replaceAndAppendScalarValuesRecursive re-numbers associative arrays with non-consecutively numbered integer-only keys added
Updated by Stephan Jorek over 3 years ago
- Related to deleted (Bug #94729: Method ArrayUtility::replaceAndAppendScalarValuesRecursive re-numbers associative arrays with non-consecutively numbered integer-only keys)
Updated by Stephan Jorek over 3 years ago
- Has duplicate Bug #94729: Method ArrayUtility::replaceAndAppendScalarValuesRecursive re-numbers associative arrays with non-consecutively numbered integer-only keys added