‪TYPO3CMS  10.4
CreatablePropertyCollectionElementPropertiesValidator.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 
22 
27 {
28 
43  public function ‪__invoke(string $key, $value)
44  {
45  $dto = $this->validationDto->withPropertyPath($key);
46 
47  if ($this->‪getConfigurationService()->isPropertyCollectionPropertyDefinedInFormEditorSetup($dto)) {
48  if ($this->‪getConfigurationService()->propertyCollectionPropertyHasLimitedAllowedValuesDefinedWithinFormEditorSetup($dto)) {
49  $this->‪validatePropertyCollectionPropertyValue($value, $dto);
50  }
51  } elseif (
52  $this->‪getConfigurationService()->isPropertyCollectionPropertyDefinedInPredefinedDefaultsInFormEditorSetup($dto)
53  && !‪ArrayUtility::isValidPath($this->currentElement, $this->‪buildHmacDataPath($dto->getPropertyPath()), '.')
54  ) {
56  } else {
58  $this->currentElement,
59  $value,
60  $this->sessionToken,
61  $dto
62  );
63  }
64  }
65 
75  $value,
76  ‪ValidationDto $dto
77  ): void {
78  // If the property collection element is newly created, we have to compare the $value (form definition) with $predefinedDefaultValue (form setup)
79  // to check the integrity (at this time we don't have a hmac on the value to check the integrity)
81  if ($value !== $predefinedDefaultValue) {
82  $throwException = true;
83 
84  if (is_string($predefinedDefaultValue)) {
85  // Last chance:
86  // Get all translations (from all backend languages) for the untranslated! $predefinedDefaultValue and
87  // compare the (already translated) $value (from the form definition) against the possible
88  // translations from $predefinedDefaultValue.
89  $untranslatedPredefinedDefaultValue = $this->‪getConfigurationService()->‪getPropertyCollectionPredefinedDefaultValueFromFormEditorSetup($dto, false);
91  $untranslatedPredefinedDefaultValue,
92  $dto->‪getPrototypeName()
93  );
94 
95  if (in_array($value, $translations, true)) {
96  $throwException = false;
97  }
98  }
99 
100  if ($throwException) {
101  $message = 'The value "%s" of property "%s" (form element "%s" / "%s.%s") is not equal to the default value "%s" #1528591502';
102  throw new ‪PropertyException(
103  sprintf(
104  $message,
105  $value,
106  $dto->‪getPropertyPath(),
110  $predefinedDefaultValue
111  ),
112  1528591502
113  );
114  }
115  }
116  }
117 
127  $value,
128  ‪ValidationDto $dto
129  ): void {
131 
132  if (!in_array($value, $allowedValues, true)) {
134  // Compare the $value against the untranslated set of allowed values
135  if (in_array($value, $untranslatedAllowedValues, true)) {
136  // All good, $value is within the untranslated set of allowed values
137  return;
138  }
139  // Get all translations (from all backend languages) for the untranslated! $allowedValues and
140  // compare the (already translated) $value (from the form definition) against all possible
141  // translations for $untranslatedAllowedValues.
142  $allPossibleAllowedValuesTranslations = $this->‪getConfigurationService()->‪getAllBackendTranslationsForTranslationKeys(
143  $untranslatedAllowedValues,
144  $dto->‪getPrototypeName()
145  );
146 
147  foreach ($allPossibleAllowedValuesTranslations as $translations) {
148  if (in_array($value, $translations, true)) {
149  // All good, $value is within the set of translated allowed values
150  return;
151  }
152  }
153 
154  // Last chance:
155  // If $value is not configured within the form setup as an allowed value
156  // but was written within the form definition by hand (and therefore contains a hmac),
157  // check if $value is manipulated.
158  // If $value has no hmac or if the hmac exists but is not valid,
159  // then $this->validatePropertyCollectionElementPropertyValueByHmacData() will
160  // throw an exception.
162  $this->currentElement,
163  $value,
164  $this->sessionToken,
165  $dto
166  );
167  }
168  }
169 }
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\ValidationDto\getPrototypeName
‪string getPrototypeName()
Definition: ValidationDto.php:76
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\CreatablePropertyCollectionElementPropertiesValidator\validatePropertyCollectionElementPredefinedDefaultValue
‪validatePropertyCollectionElementPredefinedDefaultValue( $value, ValidationDto $dto)
Definition: CreatablePropertyCollectionElementPropertiesValidator.php:74
‪TYPO3\CMS\Extbase\Property\Exception
Definition: DuplicateObjectException.php:18
‪TYPO3\CMS\Form\Domain\Configuration\ConfigurationService\getAllowedValuesForPropertyCollectionPropertyFromFormEditorSetup
‪array getAllowedValuesForPropertyCollectionPropertyFromFormEditorSetup(ValidationDto $dto, bool $translated=true)
Definition: ConfigurationService.php:278
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\ValidationDto
Definition: ValidationDto.php:23
‪TYPO3\CMS\Core\Utility\ArrayUtility\isValidPath
‪static bool isValidPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:144
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\CreatablePropertyCollectionElementPropertiesValidator\__invoke
‪__invoke(string $key, $value)
Definition: CreatablePropertyCollectionElementPropertiesValidator.php:43
‪TYPO3\CMS\Form\Domain\Configuration\ConfigurationService\getAllBackendTranslationsForTranslationKeys
‪array getAllBackendTranslationsForTranslationKeys(array $keys, string $prototypeName)
Definition: ConfigurationService.php:525
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\AbstractValidator\buildHmacDataPath
‪string buildHmacDataPath(string $propertyPath)
Definition: AbstractValidator.php:65
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\ValidationDto\getPropertyPath
‪string getPropertyPath()
Definition: ValidationDto.php:100
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\ValidationDto\getFormElementIdentifier
‪string getFormElementIdentifier()
Definition: ValidationDto.php:92
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\CollectionBasedValidator
Definition: CollectionBasedValidator.php:27
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\CreatablePropertyCollectionElementPropertiesValidator
Definition: CreatablePropertyCollectionElementPropertiesValidator.php:27
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\ValidationDto\getPropertyCollectionElementIdentifier
‪string getPropertyCollectionElementIdentifier()
Definition: ValidationDto.php:116
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\CollectionBasedValidator\validatePropertyCollectionElementPropertyValueByHmacData
‪validatePropertyCollectionElementPropertyValueByHmacData(array $currentElement, $value, string $sessionToken, ValidationDto $dto)
Definition: CollectionBasedValidator.php:40
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators
Definition: AbstractValidator.php:18
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\AbstractValidator\getConfigurationService
‪ConfigurationService getConfigurationService()
Definition: AbstractValidator.php:85
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\CreatablePropertyCollectionElementPropertiesValidator\validatePropertyCollectionPropertyValue
‪validatePropertyCollectionPropertyValue( $value, ValidationDto $dto)
Definition: CreatablePropertyCollectionElementPropertiesValidator.php:126
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Form\Domain\Configuration\ConfigurationService\getPropertyCollectionPredefinedDefaultValueFromFormEditorSetup
‪mixed getPropertyCollectionPredefinedDefaultValueFromFormEditorSetup(ValidationDto $dto, bool $translated=true)
Definition: ConfigurationService.php:436
‪TYPO3\CMS\Form\Domain\Configuration\Exception\PropertyException
Definition: PropertyException.php:26
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\ValidationDto\getPropertyCollectionName
‪string getPropertyCollectionName()
Definition: ValidationDto.php:108
‪TYPO3\CMS\Form\Domain\Configuration\ConfigurationService\getAllBackendTranslationsForTranslationKey
‪array getAllBackendTranslationsForTranslationKey(string $key, string $prototypeName)
Definition: ConfigurationService.php:544