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