#101541The data type of validator options is neither respected nor documented, the required flag is not documented
Description
When extending \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator to write a custom validator having options, for example when doing this in combination with ext:form, one has to specifiy the $supportedOptions array inside the validator class, like so
protected $supportedOptions = [
'optionOne' => [1, 'Some option', 'int'],
'optionTwo' => [5, 'another option', 'int']
];
Containing the type of the value as the third array element.
When I dump what is in the final values in my options ($this->getOptions() or directly $this->options) I can see that the int cast is not happening. For example, when using this in combination with ext:form the option values come from the YAML which contains strings. So my options does contain '5' instead of 5.
Shouldn’t the configured option types in some way be respected (at least in the documentation of this API)? What I’m saying: I’m not even sure whether I just made a bug report, or even a feature request or simply reported missing/inconsistent documentation.
https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ExtensionArchitecture/Extbase/Reference/Validation/Index.html (and subpages) has nothing about it. What is the intention of this configuration? Is this a left-over or planned to be used in the future?
And the fourth flag (“option required or not”) is also not documented, but it is respected in code.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Fix this issue
Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch
- Commit message
-
[BUGFIX] The data type of validator options is neither respected nor documented, the required flag is not documented Resolves: #101541 Releases: main
History 5
-
S P commented and changed subject
The type of validator options is not respectedThe data type of validator options is neither respected nor documented TYPO3 Version1213 <span data-processor="relativetime" data-value="2025-01-09T10:41:30+00:00" > 01/09/25, 10:41 </span>Still valid on v13. The validator option API is not documented at all:
So it remains unclear what this type hinting is supposed to do, what its purpose is, or whether it is a left-over or not-yet-implemented.
It seems from a look in the code that a boolean fourth parameter can also declare options as required, which is also undocumented.
-
Torben Hansen commented <span data-processor="relativetime" data-value="2025-02-15T18:19:19+00:00" > 02/15/25, 18:19 </span>
And just to add some more confusion to this issue: There is also an undocumented 4th array index for validator options, which definies, if a validator option is required or not.
protected $supportedOptions = [ 'minimum' => [0, 'Minimum length for a valid string', 'integer', true], ];If the 4th array index in this example is
true, resulting in the validator option being required when used. If no option is provided on usage, anInvalidValidationOptionsExceptionis thrown.Flow has it at least somehow documented in code: https://github.com/neos/flow/blob/8.3/Classes/Validation/Validator/AbstractValidator.php#L46
Maybe we could use the chance in v14 and use an array key based approach, where this is more clear (see next example)
protected $supportedOptions = [ 'minimum' => [ 'default' => 0, 'description' => 'Minimum length for a valid string', 'type' => 'integer', 'required' => true, ], ];We could automatically transform the “old” index based array to the new structure in
AbstractValidatorand additionally implement a type check. -
Lina Wolf commented <span data-processor="relativetime" data-value="2025-03-25T06:30:04+00:00" > 03/25/25, 06:30 </span>
How about switching to something like `#[Option]` arguments instead? Those could be automatically documented etc
-
S P commented and changed subject
The data type of validator options is neither respected nor documentedThe data type of validator options is neither respected nor documented, the required flag is not documented description TYPO3 Version1314 <span data-processor="relativetime" data-value="2026-06-12T05:42:10+00:00" > 06/12/26, 05:42 </span>Still so on v14. 3rd parameter (type) is ignored, 4th parameter (required yes/no) is not documented (but parsed).
As far as I can see, this was never evaluated in Extbase at some time, so the 3rd array parameter is most likely unused. Typecasting is IMO no option here, since we also have validators, which declare
boolean|string|integerfor the parameter, so basically the value could just be used for type hinting.