Skip to content

Commit 1e0e2e2

Browse files
[BUGFIX] Make StringLengthValidator configuration v12+ compatible (#34)
The validator API has changed in v12, configuration doesn't happen via constructor arguments anymore, but via calling `setOptions()`. This commit adds a version switch to respect several versions of the API.
1 parent 10284c3 commit 1e0e2e2

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

Classes/Domain/Factory/SuggestFormFactory.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Evoweb\Sessionplaner\Enum\SessionLevelEnum;
1616
use Evoweb\Sessionplaner\Enum\SessionRequestTypeEnum;
1717
use Evoweb\Sessionplaner\Enum\SessionTypeEnum;
18+
use TYPO3\CMS\Core\Information\Typo3Version;
1819
use TYPO3\CMS\Core\Utility\GeneralUtility;
1920
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
2021
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
@@ -157,7 +158,14 @@ public function build(array $configuration, string $prototypeName = null): FormD
157158
$this->getLocalizedLabel($settings['suggest']['fields']['description']['description'])
158159
);
159160
$descriptionField->addValidator(GeneralUtility::makeInstance(NotEmptyValidator::class));
160-
$descriptionField->addValidator(GeneralUtility::makeInstance(StringLengthValidator::class, ['minimum' => 5]));
161+
162+
if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) {
163+
$stringLengthValidator = GeneralUtility::makeInstance(StringLengthValidator::class, ['minimum' => 5]);
164+
} else {
165+
$stringLengthValidator = GeneralUtility::makeInstance(StringLengthValidator::class);
166+
$stringLengthValidator->setOptions(['minimum' => 5]);
167+
}
168+
$descriptionField->addValidator($stringLengthValidator);
161169

162170
if ($settings['suggest']['fields']['length']['enable']) {
163171
/** @var GenericFormElement $lengthField */

0 commit comments

Comments
 (0)