‪TYPO3CMS  ‪main
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 {
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 
72  $value,
73  ‪ValidationDto $dto
74  ): void {
75  // If the property collection element is newly created, we have to compare the $value (form definition) with $predefinedDefaultValue (form setup)
76  // to check the integrity (at this time we don't have a hmac on the value to check the integrity)
77  $predefinedDefaultValue = $this->‪getConfigurationService()->getPropertyCollectionPredefinedDefaultValueFromFormEditorSetup($dto);
78  if ($value !== $predefinedDefaultValue) {
79  $throwException = true;
80 
81  if (is_string($predefinedDefaultValue)) {
82  // Last chance:
83  // Get all translations (from all backend languages) for the untranslated! $predefinedDefaultValue and
84  // compare the (already translated) $value (from the form definition) against the possible
85  // translations from $predefinedDefaultValue.
86  $untranslatedPredefinedDefaultValue = $this->‪getConfigurationService()->getPropertyCollectionPredefinedDefaultValueFromFormEditorSetup($dto, false);
87  $translations = $this->‪getConfigurationService()->getAllBackendTranslationsForTranslationKey(
88  $untranslatedPredefinedDefaultValue,
89  $dto->‪getPrototypeName()
90  );
91 
92  if (in_array($value, $translations, true)) {
93  $throwException = false;
94  }
95  }
96 
97  if ($throwException) {
98  $message = 'The value "%s" of property "%s" (form element "%s" / "%s.%s") is not equal to the default value "%s" #1528591502';
99  throw new ‪PropertyException(
100  sprintf(
101  $message,
102  $value,
103  $dto->‪getPropertyPath(),
107  $predefinedDefaultValue
108  ),
109  1528591502
110  );
111  }
112  }
113  }
114 
123  $value,
124  ‪ValidationDto $dto
125  ): void {
126  $allowedValues = $this->‪getConfigurationService()->getAllowedValuesForPropertyCollectionPropertyFromFormEditorSetup($dto);
127 
128  if (!in_array($value, $allowedValues, true)) {
129  $untranslatedAllowedValues = $this->‪getConfigurationService()->getAllowedValuesForPropertyCollectionPropertyFromFormEditorSetup($dto, false);
130  // Compare the $value against the untranslated set of allowed values
131  if (in_array($value, $untranslatedAllowedValues, true)) {
132  // All good, $value is within the untranslated set of allowed values
133  return;
134  }
135  // Get all translations (from all backend languages) for the untranslated! $allowedValues and
136  // compare the (already translated) $value (from the form definition) against all possible
137  // translations for $untranslatedAllowedValues.
138  $allPossibleAllowedValuesTranslations = $this->‪getConfigurationService()->getAllBackendTranslationsForTranslationKeys(
139  $untranslatedAllowedValues,
140  $dto->‪getPrototypeName()
141  );
142 
143  foreach ($allPossibleAllowedValuesTranslations as $translations) {
144  if (in_array($value, $translations, true)) {
145  // All good, $value is within the set of translated allowed values
146  return;
147  }
148  }
149 
150  // Last chance:
151  // If $value is not configured within the form setup as an allowed value
152  // but was written within the form definition by hand (and therefore contains a hmac),
153  // check if $value is manipulated.
154  // If $value has no hmac or if the hmac exists but is not valid,
155  // then $this->validatePropertyCollectionElementPropertyValueByHmacData() will
156  // throw an exception.
158  $this->currentElement,
159  $value,
160  $this->sessionToken,
161  $dto
162  );
163  }
164  }
165 }
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\ValidationDto\getPropertyCollectionName
‪getPropertyCollectionName()
Definition: ValidationDto.php:84
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\CreatablePropertyCollectionElementPropertiesValidator\validatePropertyCollectionElementPredefinedDefaultValue
‪validatePropertyCollectionElementPredefinedDefaultValue( $value, ValidationDto $dto)
Definition: CreatablePropertyCollectionElementPropertiesValidator.php:71
‪TYPO3\CMS\Extbase\Property\Exception
Definition: DuplicateObjectException.php:18
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\ValidationDto
Definition: ValidationDto.php:23
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\CreatablePropertyCollectionElementPropertiesValidator\__invoke
‪__invoke(string $key, $value)
Definition: CreatablePropertyCollectionElementPropertiesValidator.php:41
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\ValidationDto\getFormElementIdentifier
‪getFormElementIdentifier()
Definition: ValidationDto.php:74
‪TYPO3\CMS\Core\Utility\ArrayUtility\isValidPath
‪static bool isValidPath(array $array, array|string $path, string $delimiter='/')
Definition: ArrayUtility.php:141
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\ValidationDto\getPropertyCollectionElementIdentifier
‪getPropertyCollectionElementIdentifier()
Definition: ValidationDto.php:89
‪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\CollectionBasedValidator\validatePropertyCollectionElementPropertyValueByHmacData
‪validatePropertyCollectionElementPropertyValueByHmacData(array $currentElement, $value, string $sessionToken, ValidationDto $dto)
Definition: CollectionBasedValidator.php:36
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators
Definition: AbstractValidator.php:18
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\AbstractValidator\buildHmacDataPath
‪buildHmacDataPath(string $propertyPath)
Definition: AbstractValidator.php:51
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\CreatablePropertyCollectionElementPropertiesValidator\validatePropertyCollectionPropertyValue
‪validatePropertyCollectionPropertyValue( $value, ValidationDto $dto)
Definition: CreatablePropertyCollectionElementPropertiesValidator.php:122
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\ValidationDto\getPropertyPath
‪getPropertyPath()
Definition: ValidationDto.php:79
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:26
‪TYPO3\CMS\Form\Domain\Configuration\Exception\PropertyException
Definition: PropertyException.php:25
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\ValidationDto\getPrototypeName
‪getPrototypeName()
Definition: ValidationDto.php:64
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\AbstractValidator\getConfigurationService
‪getConfigurationService()
Definition: AbstractValidator.php:65