Project

General

Profile

Actions

Bug #94852

open

Importing YAML files with numeric keys yields unexpected results

Added by Johannes Nielsen almost 3 years ago. Updated almost 3 years ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2021-08-12
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
10
PHP Version:
7.3
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

When using imports in YAML files (e.g. in forms framework), numeric keys are not respected because the YamlFileLoader calls ArrayUtility::replaceAndAppendScalarValuesRecursive which in turn calls array_merge, which does not respect numeric keys.
As an example, say one has three YAML files:

#imports.yaml:
imports:
  - { resource: './file1.yaml' }
  - { resource: './file2.yaml' }

#file1.yaml:
TYPO3:
  CMS:
    Form:
      prototypes:
        standard:
          formElementsDefinition:
            Form:
              formEditor:
                editors:
                  900:
                    selectOptions:
                      35:
                        value: 'FirstValue'
                        label: 'First option'

#file2.yaml:
TYPO3:
  CMS:
    Form:
      prototypes:
        standard:
          formElementsDefinition:
            Form:
              formEditor:
                editors:
                  900:
                    selectOptions:
                      45:
                        value: 'SecondValue'
                        label: 'Second option'

The expected result would be:

TYPO3:
  CMS:
    Form:
      prototypes:
        standard:
          formElementsDefinition:
            Form:
              formEditor:
                editors:
                  900: # 900 is respected as key
                    selectOptions:
                      35:
                        value: 'FirstValue'
                        label: 'First option'
                      45:
                        value: 'FirstValue'
                        label: 'First option'

However, the actual result is

TYPO3:
  CMS:
    Form:
      prototypes:
        standard:
          formElementsDefinition:
            Form:
              formEditor:
                editors:
                  # array_merge is called on the editors array, so that numeric keys get lost
                  0:
                    selectOptions:
                      35:
                        value: 'FirstValue'
                        label: 'First option'
                  1:
                    selectOptions:
                      45:
                        value: 'FirstValue'
                        label: 'First option'

As a workaround, one can add an empty non-numeric key to the second import - given that the order is known, which could be reversed if the corresponding feature-flag is set, so it would be better to add this to all imports:

#file2.yaml:
TYPO3:
  CMS:
    Form:
      prototypes:
        standard:
          formElementsDefinition:
            Form:
              formEditor:
                editors:
                  _: # This makes this an associative array and yields the desired result plus this empty property 
                  900:
                    selectOptions:
                      45:
                        value: 'SecondValue'
                        label: 'Second option'
Actions #1

Updated by Johannes Nielsen almost 3 years ago

  • Subject changed from Importing YAML files with numberic keys yields unexpected results to Importing YAML files with numeric keys yields unexpected results
Actions

Also available in: Atom PDF