Skip to content
Snippets Groups Projects
Commit 7b6ed162 authored by Mathias Brodala's avatar Mathias Brodala Committed by Christian Kuhn
Browse files

[FEATURE] Allow custom default in getFormValue() conditions function

Resolves: #102077
Releases: main
Change-Id: I6c5428f97e35807dbb22db0e4d862b62ab7c84cf
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81307


Tested-by: default avatarcore-ci <typo3@b13.com>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: default avatarStefan Bürk <stefan@buerk.tech>
parent 1fa0a832
Branches
Tags
No related merge requests found
.. include:: /Includes.rst.txt
.. _feature-102077-1696240251:
===================================================================================
Feature: #102077 - Allow custom default value in getFormValue() conditions function
===================================================================================
See :issue:`102077`
Description
===========
The `getFormValue()` function can be used in conditions of form variants to
safely retrieve form values. Before, `null` was returned as default value. This
made it impossible to use this, for example, with the `in` operator to check
values in multi-value form fields. An additional check was necessary to avoid
type issues:
.. code-block:: yaml
variants:
- identifier: variant-1
condition: 'getFormValue("multiCheckbox") && "foo" in getFormValue("multiCheckbox")'
A second argument has been added to this function to set a custom default value.
This allows shortening conditions accordingly:
.. code-block:: yaml
variants:
- identifier: variant-1
condition: '"foo" in getFormValue("multiCheckbox", [])'
Impact
======
Form variant conditions can be shortened.
.. index:: YAML, ext:form
......@@ -45,8 +45,8 @@ class FormConditionFunctionsProvider implements ExpressionFunctionProviderInterf
return new ExpressionFunction(
'getFormValue',
static fn() => null, // Not implemented, we only use the evaluator
static function ($arguments, $field) {
return $arguments['formValues'][$field] ?? null;
static function ($arguments, $field, $default = null) {
return $arguments['formValues'][$field] ?? $default;
}
);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment