Project

General

Profile

Actions

Bug #89204

closed

Form variants: Override ignored for arrays, if a value is removed

Added by Christian Eßl about 5 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Should have
Category:
Form Framework
Start date:
2019-09-19
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
9
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:
Remote Sprint

Description

Take this SingleSelect as an example:

-
        properties:
          options:
            '': '---'
            mr: Mr.
            mrs: Mrs.
            miss: Miss
        defaultValue: ''
        type: SingleSelect
        identifier: salulation
        label: Salutation
        variants:
          -
            identifier: salulation-variant
            condition: 'siteLanguage("locale") == "zh_CN.utf-8"'
            properties:
              options:
                '': '---'
                mr: Mr.
                mrs: Mrs.

In case of the specified variant, a single option item shall be removed from the select. This will be ignored.

The reason is the following code in AbstractFormElement.php:

/**
     * Set a property of the element
     *
     * @param string $key
     * @param mixed $value
     */
    public function setProperty(string $key, $value)
    {
        if (is_array($value) && isset($this->properties[$key]) && is_array($this->properties[$key])) {
            ArrayUtility::mergeRecursiveWithOverrule($this->properties[$key], $value);
            $this->properties[$key] = ArrayUtility::removeNullValuesRecursive($this->properties[$key]);
        } elseif ($value === null) {
            unset($this->properties[$key]);
        } else {
            $this->properties[$key] = $value;
        }
    }

Overriding an array (in this case "options") will alway lead to an array_merge of the original and the new array. So as of now, you cannot remove an array item with the variants feature.

Actions

Also available in: Atom PDF