‪TYPO3CMS  ‪main
FormConditionFunctionsProvider.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Symfony\Component\ExpressionLanguage\ExpressionFunction;
21 use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
23 
27 class ‪FormConditionFunctionsProvider implements ExpressionFunctionProviderInterface
28 {
32  public function ‪getFunctions(): array
33  {
34  return [
35  $this->‪getFormValueFunction(),
37  ];
38  }
39 
43  protected function ‪getFormValueFunction(): ExpressionFunction
44  {
45  return new ExpressionFunction(
46  'getFormValue',
47  static fn() => null, // Not implemented, we only use the evaluator
48  static function ($arguments, $field, $default = null) {
49  return $arguments['formValues'][$field] ?? $default;
50  }
51  );
52  }
53 
54  protected function ‪getRootFormPropertyFunction(): ExpressionFunction
55  {
56  return new ExpressionFunction(
57  'getRootFormProperty',
58  static fn() => null, // Not implemented, we only use the evaluator
59  static function ($arguments, $property) {
60  $formDefinition = $arguments['formRuntime']->getFormDefinition();
61  try {
62  $value = ‪ObjectAccess::getPropertyPath($formDefinition, $property);
63  } catch (\‪Exception) {
64  $value = null;
65  }
66  return $value;
67  }
68  );
69  }
70 }
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess\getPropertyPath
‪static mixed getPropertyPath(object|array $subject, string $propertyPath)
Definition: ObjectAccess.php:128
‪TYPO3\CMS\Form\Domain\Condition\Functions\FormConditionFunctionsProvider\getFunctions
‪ExpressionFunction[] getFunctions()
Definition: FormConditionFunctionsProvider.php:32
‪TYPO3\CMS\Form\Domain\Condition\Functions
Definition: FormConditionFunctionsProvider.php:18
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess
Definition: ObjectAccess.php:39
‪TYPO3\CMS\Form\Domain\Condition\Functions\FormConditionFunctionsProvider\getRootFormPropertyFunction
‪getRootFormPropertyFunction()
Definition: FormConditionFunctionsProvider.php:54
‪TYPO3\CMS\Form\Domain\Exception
Definition: Exception.php:25
‪TYPO3\CMS\Form\Domain\Condition\Functions\FormConditionFunctionsProvider
Definition: FormConditionFunctionsProvider.php:28
‪TYPO3\CMS\Form\Domain\Condition\Functions\FormConditionFunctionsProvider\getFormValueFunction
‪getFormValueFunction()
Definition: FormConditionFunctionsProvider.php:43