Skip to content

Commit

Permalink
[BUGFIX] Make StringLengthValidator configuration v12+ compatible (#34
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
andreaskienast authored Jan 25, 2024
1 parent 10284c3 commit 1e0e2e2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Classes/Domain/Factory/SuggestFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Evoweb\Sessionplaner\Enum\SessionLevelEnum;
use Evoweb\Sessionplaner\Enum\SessionRequestTypeEnum;
use Evoweb\Sessionplaner\Enum\SessionTypeEnum;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
Expand Down Expand Up @@ -157,7 +158,14 @@ public function build(array $configuration, string $prototypeName = null): FormD
$this->getLocalizedLabel($settings['suggest']['fields']['description']['description'])
);
$descriptionField->addValidator(GeneralUtility::makeInstance(NotEmptyValidator::class));
$descriptionField->addValidator(GeneralUtility::makeInstance(StringLengthValidator::class, ['minimum' => 5]));

if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) {
$stringLengthValidator = GeneralUtility::makeInstance(StringLengthValidator::class, ['minimum' => 5]);
} else {
$stringLengthValidator = GeneralUtility::makeInstance(StringLengthValidator::class);
$stringLengthValidator->setOptions(['minimum' => 5]);
}
$descriptionField->addValidator($stringLengthValidator);

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

0 comments on commit 1e0e2e2

Please sign in to comment.