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