This documentation is not using the current rendering mechanism and will be deleted by December 31st, 2020. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.
Extbase brings a way to easily tell TYPO3 when a property is valid: by using annotations on class properties, Extbase will find which properties should be validated. To do so, you have to use the
@validate annotation inside the phpDoc section of that property.
Of course, you can create and use any validator you want in your configuration object – if it does follow Extbase validator standards.
/** * @var string * @validate TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator */ protected $name;
To reduce the length of a
@validate annotation, you can use the following shortcut naming convention:
Moreover, a validator from the core of Extbase can be used by writing only its name.
/** * @var string * @validate NotEmpty * @validate EmailAddress * @validate MyVendor.MyExtension:Custom */ protected $email;
Please be aware that only validators which follow the Extbase validator naming convention can use the shortened notation:
- The validator must be in the following namespace of your extension:
- The validator class must end with
Oh, by the way, you can use this notation everywhere Extbase parses the
@validate annotation, for instance in your controller or model classes. :-)
Some validators may require parameters, for instance
NumberRangeValidator from Extbase needs the following parameters:
maximum. To do so, use the following notation:
/** * @validate NumberRange(minimum: 0, maximum: 100) */
You can attach several validators to the same property. For instance:
/** * @var string * @validate NotEmpty * @validate EmailAddress * @validate VendorName.ExtensionName:CustomValidator */ protected $email;