diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/Attributes.rst b/Documentation/ExtensionArchitecture/Extbase/Reference/Attributes.rst index 19b5dbdc88..048eae1eff 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/Attributes.rst +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/Attributes.rst @@ -38,7 +38,7 @@ for the attribute :php:`Lazy`: Attributes provided by Extbase ============================== -The following attributes are provided Extbase: +The following attributes are provided by Extbase: .. _extbase-annotation-validate: .. _extbase-attribute-validate: @@ -46,8 +46,9 @@ The following attributes are provided Extbase: Validate -------- -:php:`\TYPO3\CMS\Extbase\Attribute\Validate`: Allows to configure validators -for properties and method arguments. See :ref:`extbase_validation` for details. +:php:`\TYPO3\CMS\Extbase\Attribute\Validate(validator: "...", options: [...])`: +Allows to configure validators for properties and method arguments. +See :ref:`extbase_validation` for details. Can be used in the context of a model property. @@ -65,11 +66,11 @@ to possible domain model validators. IgnoreValidation ---------------- -:php:`\TYPO3\CMS\Extbase\Attribute\IgnoreValidation()`: Allows to ignore -all Extbase default validations for a given argument (for example a domain -model object). +:php:`\TYPO3\CMS\Extbase\Attribute\IgnoreValidation`: +Allows to ignore all Extbase default validations for a given argument +(for example a domain model object). -Used in context of a controller action. +Used in context of a controller action argument. **Example:** @@ -88,7 +89,7 @@ Read more about this on https://usetypo3.com/dtos-in-extbase/ or see a https://github.com/garvinhicking/gh_validationdummy/ .. warning:: - `IgnoreValidation()` must not be used for domain models supporting + `IgnoreValidation` must not be used for domain models supporting extbase file uploads, because this leads to a property mapping error. .. _extbase-annotation-orm: @@ -105,8 +106,8 @@ The following attributes can only be used on model properties: Cascade ~~~~~~~ -:php:`\TYPO3\CMS\Extbase\Attribute\ORM\Cascade("remove")`: Allows to remove -child entities during deletion of aggregate root. +:php:`\TYPO3\CMS\Extbase\Attribute\ORM\Cascade(value: "remove")`: +Allows to remove child entities during deletion of aggregate root. Extbase only supports the option "remove". @@ -121,8 +122,8 @@ Extbase only supports the option "remove". Transient ~~~~~~~~~ -:php:`\TYPO3\CMS\Extbase\Attribute\ORM\Transient`: Marks property as transient -(not persisted). +:php:`\TYPO3\CMS\Extbase\Attribute\ORM\Transient`: +Marks property as transient (not persisted). **Example:** @@ -135,8 +136,8 @@ Transient Lazy ~~~~ -:php:`\TYPO3\CMS\Extbase\Attribute\ORM\Lazy`: Marks model property to be loaded -lazily on first access. +:php:`\TYPO3\CMS\Extbase\Attribute\ORM\Lazy`: +Marks model property to be loaded lazily on first access. .. note:: Lazy loading can greatly improve the performance of your actions. @@ -161,6 +162,51 @@ are frequently combined: Several validations can also be combined. See :ref:`extbase_validation` for details. +.. _extbase-attributes-migration-config-array: + +Migration and version compatibility (configuration arrays → named arguments) +=========================================================================== + +With TYPO3 v14, passing a configuration array as the first argument to Extbase +attributes (for example :php:`#[Validate([ ... ])]`, :php:`#[IgnoreValidation([ ... ])]`, +:php:`#[FileUpload([ ... ])]` or :php:`#[Cascade([ ... ])]`) has been deprecated +(:ref:`Deprecation #97559 `). +TYPO3 v14 introduces a property-based configuration syntax using named attribute +arguments. + +The array-based syntax continues to work in TYPO3 v14 but will be removed with +TYPO3 v15. + +.. important:: + + There is **no attribute configuration syntax that is compatible with both + TYPO3 v13 and TYPO3 v14**. + + PHP attributes are parsed statically and cannot be conditionally defined + based on the TYPO3 version. Extensions supporting TYPO3 v13 and v14 in the + same release must therefore continue to use the array-based syntax and accept + the deprecation warning in TYPO3 v14. + +.. code-block:: php + :caption: Example (TYPO3 v13 and v14 compatible) + + // TODO: Switch to named arguments when dropping TYPO3 v13 support (Deprecation #97559). + #[Cascade([ + 'value' => 'remove', + ])] + +.. code-block:: php + :caption: Example (TYPO3 v14+, recommended) + + #[Cascade(value: 'remove')] + +TYPO3 Rector (:composer:`ssch/typo3-rector`) has rule +:php:`\Ssch\TYPO3Rector\TYPO314\v0\MigratePassingAnArrayOfConfigurationValuesToExtbaseAttributesRector` to +automatically migrate from the annotation syntax to the attribute syntax. + +.. seealso:: + * `MigratePassingAnArrayOfConfigurationValuesToExtbaseAttributesRector `_ + .. _extbase-annotation-migration: Migrate from Extbase annotations to attributes diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/DataObjects/_codesnippets/MeasurementsDtoValidation.php b/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/DataObjects/_codesnippets/MeasurementsDtoValidation.php index 9c981f9a47..0d526d0acc 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/DataObjects/_codesnippets/MeasurementsDtoValidation.php +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/DataObjects/_codesnippets/MeasurementsDtoValidation.php @@ -9,14 +9,15 @@ final class MeasurementsDto { // Ensure that the height is in meters, not centimeters - #[Validate(['validator' => 'NotEmpty'])] - #[Validate([ - 'validator' => 'NumberRange', - 'options' => ['minimum' => 0.5, 'maximum' => 2.5], - ])] + #[Validate(validator: 'NotEmpty')] + #[Validate( + validator: 'NumberRange', + options: ['minimum' => 0.5, 'maximum' => 2.5], + )] private float $height; + // Weight must not be empty - #[Validate(['validator' => 'NotEmpty'])] + #[Validate(validator: 'NotEmpty')] private int $weight; public function __construct(?float $height, ?int $weight) diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/PropertyTypes/_codesnippets/_BoolExample.php b/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/PropertyTypes/_codesnippets/_BoolExample.php index 16334c9fe3..02fc55c2d4 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/PropertyTypes/_codesnippets/_BoolExample.php +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/PropertyTypes/_codesnippets/_BoolExample.php @@ -11,9 +11,9 @@ class BoolExample extends AbstractEntity { public bool $wantsNewsletter = false; - #[Validate([ - 'validator' => 'Boolean', - 'options' => ['is' => true], - ])] + #[Validate( + validator: 'Boolean', + options: ['is' => true], + )] public bool $acceptedPrivacyPolicy = false; } diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/PropertyTypes/_codesnippets/_IntExample.php b/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/PropertyTypes/_codesnippets/_IntExample.php index da47db4df1..3e83bb27ad 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/PropertyTypes/_codesnippets/_IntExample.php +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/PropertyTypes/_codesnippets/_IntExample.php @@ -9,15 +9,15 @@ class IntExample extends AbstractEntity { - #[Validate([ - 'validator' => 'NumberRange', - 'options' => ['minimum' => 0, 'maximum' => 10], - ])] + #[Validate( + validator: 'NumberRange', + options: ['minimum' => 0, 'maximum' => 10], + )] public int $importance = 0; - #[Validate([ - 'validator' => 'NumberRange', - 'options' => ['minimum' => 0, 'maximum' => 3], - ])] + #[Validate( + validator: 'NumberRange', + options: ['minimum' => 0, 'maximum' => 3], + )] public int $status = 0; } diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/PropertyTypes/_codesnippets/_StringExample.php b/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/PropertyTypes/_codesnippets/_StringExample.php index f2f7ad2470..72056362ef 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/PropertyTypes/_codesnippets/_StringExample.php +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/Domain/Model/PropertyTypes/_codesnippets/_StringExample.php @@ -5,19 +5,33 @@ namespace Vendor\Extension\Domain\Model; use TYPO3\CMS\Extbase\Attribute\Validate; +use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; -class StringExample extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity +class StringExample extends AbstractEntity { - #[Validate(['validator' => 'StringLength', 'options' => ['maximum' => 255]])] + #[Validate( + validator: 'StringLength', + options: ['maximum' => 255], + )] protected string $title = ''; + public ?string $subtitle = null; + protected string $description = ''; + protected string $icon = 'fa-solid fa-star'; - #[Validate(['validator' => 'MyColorValidator'])] + + #[Validate(validator: 'MyColorValidator')] protected string $color = '#ffffff'; - #[Validate(['validator' => 'EmailAddress'])] + + #[Validate(validator: 'EmailAddress')] protected string $email = ''; + protected string $passwordHash = ''; - #[Validate(['validator' => 'StringLength', 'options' => ['maximum' => 255]])] + + #[Validate( + validator: 'StringLength', + options: ['maximum' => 255], + )] protected string $virtualValue = ''; } diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/FileUpload.rst b/Documentation/ExtensionArchitecture/Extbase/Reference/FileUpload.rst index 6808431bd8..299f9699f7 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/FileUpload.rst +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/FileUpload.rst @@ -87,6 +87,11 @@ was only possible by either: Automatic handling based on PHP attributes .......................................... +.. versionchanged:: 14.0 + Passing a configuration array to the FileUpload attribute has been deprecated. + Configuration must be provided via named attribute arguments. See + `Migration and version compatibility (TYPO3 v13 → v14) `_. + Starting with TYPO3 v13.3 it is finally possible to streamline this with commonly known Extbase logic, as implemented via :ref:`Feature: #103511 - Introduce Extbase file upload and deletion handling `. @@ -177,13 +182,18 @@ File upload configuration with the `FileUpload` attribute --------------------------------------------------------- File upload for a property of a domain model can be configured using the -newly introduced :php:`\TYPO3\CMS\Extbase\Attribute\FileUpload` attribute. +:php:`\TYPO3\CMS\Extbase\Attribute\FileUpload` attribute. + +.. versionchanged:: 14.0 + Passing a configuration array to the FileUpload attribute has been deprecated. + Configuration must be provided via named attribute arguments. See + `Migration and version compatibility (TYPO3 v13 → v14) `_. Example: .. literalinclude:: _FileUpload/_BlogExcerpt.php :caption: EXT:my_extension/Classes/Domain/Model/Blog.php (example excerpt of an Extbase domain model) - :emphasize-lines: 13-26 + :emphasize-lines: 13-29 All configuration settings of the :php:`\TYPO3\CMS\Extbase\Mvc\Controller\FileUploadConfiguration` object can @@ -208,6 +218,58 @@ It is also possible to use the :php-short:`\TYPO3\CMS\Extbase\Attribute\FileUplo file upload properties, but it is recommended to use the :php-short:`\TYPO3\CMS\Extbase\Attribute\FileUpload` attribute due to better readability. + +.. _extbase_fileupload_attribute-migration: + +Migration and version compatibility (TYPO3 v13 → v14) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +With TYPO3 v14, passing a configuration array as the first argument to Extbase +attributes (for example :php:`#[FileUpload([ ... ])]`) has been deprecated +(:ref:`Deprecation #97559 `). +A new property-based configuration syntax using named attribute arguments was +introduced with TYPO3 v14. + +The deprecated array-based syntax continues to work in TYPO3 v14 but will be +removed with TYPO3 v15. + +.. important:: + + There is **no attribute syntax that is compatible with both TYPO3 v13 and + TYPO3 v14**. + + PHP attributes are parsed statically and cannot be conditionally defined + based on the TYPO3 version. As a result, extensions that support TYPO3 v13 + and v14 within the same release must continue to use the array-based + configuration syntax and accept the deprecation warning in TYPO3 v14. + +.. code-block:: php + :caption: Example (TYPO3 v13 and v14 compatible) + + // TODO: Switch to named arguments when dropping TYPO3 v13 support (Deprecation #97559). + #[FileUpload([ + 'validation' => [ + 'required' => true, + 'maxFiles' => 1, + ], + 'uploadFolder' => '1:/user_upload/files/', + ])] + +.. code-block:: php + :caption: Example (TYPO3 v14+, recommended) + + #[FileUpload( + validation: [ + 'required' => true, + 'maxFiles' => 1, + ], + uploadFolder: '1:/user_upload/files/', + )] + +TYPO3 Rector (:composer:`ssch/typo3-rector`) has rule +:php:`\Ssch\TYPO3Rector\TYPO314\v0\MigratePassingAnArrayOfConfigurationValuesToExtbaseAttributesRector` to +automatically migrate from the annotation syntax to the attribute syntax. + .. _extbase_fileupload_attribute-manual-configuration: Manual file upload configuration @@ -319,7 +381,7 @@ Upload folder creation, when missing ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The default creation of a missing storage folder can be disabled via the -property :php:`createUploadFolderIfNotExist` of the :php:`#[FileUpload([...])]` attribute +property :php:`createUploadFolderIfNotExist` of the :php:`#[FileUpload(...)]` attribute (:php:`bool`, default :php:`true`). .. _extbase_fileupload_attribute-random-suffix: @@ -430,13 +492,18 @@ section of the :php-short:`\TYPO3\CMS\Extbase\Attribute\FileUpload` attribute: * :php:`mimeType` (for :php:`TYPO3\CMS\Extbase\Validation\Validator\MimeTypeValidator`) * :php:`allowedMimeTypes` (shorthand notation for configuration option :php:`allowedMimeTypes` of the :php:`MimeTypeValidator`, see below) +.. versionchanged:: 14.0 + Passing a configuration array to the FileUpload attribute has been deprecated. + Configuration must be provided via named attribute arguments. See + `Migration and version compatibility (TYPO3 v13 → v14) `_. + Example: .. code-block:: php :caption: Excerpt of an attribute within an Extbase domain model class - #[FileUpload([ - 'validation' => [ + #[FileUpload( + validation: [ 'required' => true, 'maxFiles' => 1, 'fileSize' => ['minimum' => '0K', 'maximum' => '2M'], @@ -447,10 +514,10 @@ Example: 'invalidExtensionMessage' => 'LLL:EXT:my_extension/...', ], 'fileExtension' => ['allowedFileExtensions' => ['jpg', 'jpeg']], - 'imageDimensions' => ['maxWidth' => 4096, 'maxHeight' => 4096] + 'imageDimensions' => ['maxWidth' => 4096, 'maxHeight' => 4096], ], - 'uploadFolder' => '1:/user_upload/extbase_single_file/', - ])] + uploadFolder: '1:/user_upload/extbase_single_file/', + )] Extbase will internally use the Extbase file upload validators for :php:`fileExtensionMimeTypeConsistency`, :php:`fileExtension`, :php:`fileSize`, :php:`mimeType` @@ -500,10 +567,15 @@ Shorthand notation for `allowedMimeTypes` Using the :php:`mimeType` configuration array, all options of the `MimeTypeValidator` can be set as sub-keys: +.. versionchanged:: 14.0 + Passing a configuration array to the FileUpload attribute has been deprecated. + Configuration must be provided via named attribute arguments. See + `Migration and version compatibility (TYPO3 v13 → v14) `_. + .. code-block:: php - #[FileUpload([ - 'validation' => [ + #[FileUpload( + validation: [ 'required' => true, 'mimeType' => [ 'allowedMimeTypes' => ['image/jpeg'], @@ -512,14 +584,13 @@ can be set as sub-keys: 'invalidExtensionMessage' => 'LLL:EXT:my_extension/...', ], ], - 'uploadFolder' => '1:/user_upload/files/', - ])] + uploadFolder: '1:/user_upload/files/', + )] The shorthand notation via :php:`'allowedMimeTypes'` continues to exist, in case only the mime type validation is needed. However, it is recommended to utilize the full :php:`'mimeType'` configuration array. - .. _extbase_fileupload_attribute-deletion: Deletion of uploaded files and file references diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/CustomValidator/Index.rst b/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/CustomValidator/Index.rst index c6eb94acab..ad228b4248 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/CustomValidator/Index.rst +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/CustomValidator/Index.rst @@ -23,6 +23,11 @@ They usually extend the :php-short:`\TYPO3\CMS\Extbase\Validation\Validator\Abst emails, numbers and strings. You do not need to implement such basic checks yourself. +.. versionchanged:: 14.0 + Passing a configuration array to the FileUpload attribute has been deprecated. + Configuration must be provided via named attribute arguments. See + `Migration and version compatibility (TYPO3 v13 → v14) `_. + .. _extbase_domain_validator-model: Custom validator for a property of the domain model diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/CustomValidator/_ObjectValidatorUsage.php b/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/CustomValidator/_ObjectValidatorUsage.php index 10e101766b..ccd2eb7080 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/CustomValidator/_ObjectValidatorUsage.php +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/CustomValidator/_ObjectValidatorUsage.php @@ -22,9 +22,9 @@ class BlogController extends ActionController * @throws NoBlogAdminAccessException */ public function updateAction( - #[Validate([ - 'validator' => BlogValidator::class, - ])] + #[Validate( + validator: BlogValidator::class, + )] Blog $blog, ): ResponseInterface { // do something diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/CustomValidator/_PropertyValidatorUsage.php b/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/CustomValidator/_PropertyValidatorUsage.php index 28e0908382..155be4cdcc 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/CustomValidator/_PropertyValidatorUsage.php +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/CustomValidator/_PropertyValidatorUsage.php @@ -10,8 +10,8 @@ class Blog extends AbstractEntity { - #[Validate([ - 'validator' => TitleValidator::class, - ])] + #[Validate( + validator: TitleValidator::class, + )] public string $title = ''; } diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/Index.rst b/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/Index.rst index 6b511fe5cd..f605aa9ce9 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/Index.rst +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/Index.rst @@ -81,10 +81,10 @@ of the current controller is called. Validation of model properties ============================== -.. versionchanged:: 13.2 - All validation messages from included Extbase validators can now be overwritten - using validator options. It is possible to provide either a translation key or - a custom message as string. +.. versionchanged:: 14.0 + Passing a configuration array to the FileUpload attribute has been deprecated. + Configuration must be provided via named attribute arguments. See + `Migration and version compatibility (TYPO3 v13 → v14) `_. You can define simple validation rules in the domain model by the attribute :ref:`extbase-attribute-validate`. @@ -98,6 +98,54 @@ In this code section the validator :php:`StringLength` provided by Extbase in class :php:`\TYPO3\CMS\Extbase\Validation\Validator\StringLengthValidator` is applied with one argument. +Validation messages from included Extbase validators can be overwritten +using validator options. It is possible to provide either a translation key or +a custom message as string. + +.. _extbase-validation-migration: + +Migration and version compatibility (TYPO3 v13 → v14) +----------------------------------------------------- + +With TYPO3 v14, passing a configuration array as the first argument to validation +attributes (for example :php:`#[Validate([ ... ])]`) has been deprecated +(:ref:`Deprecation #97559 `). +A new syntax using named attribute arguments was introduced with TYPO3 v14. + +The deprecated array-based syntax continues to work in TYPO3 v14 but will be +removed with TYPO3 v15. + +.. important:: + + There is **no validation attribute syntax that is compatible with both + TYPO3 v13 and TYPO3 v14**. + + PHP attributes are parsed statically and cannot be conditionally defined + based on the TYPO3 version. Extensions that support TYPO3 v13 and v14 in the + same release must therefore continue to use the array-based syntax and accept + the deprecation warning in TYPO3 v14. + +.. code-block:: php + :caption: Example (TYPO3 v13 and v14 compatible) + + // TODO: Switch to named arguments when dropping TYPO3 v13 support (Deprecation #97559). + #[Validate([ + 'validator' => 'StringLength', + 'options' => ['maximum' => 150], + ])] + +.. code-block:: php + :caption: Example (TYPO3 v14+, recommended) + + #[Validate( + validator: 'StringLength', + options: ['maximum' => 150], + )] + +TYPO3 Rector (:composer:`ssch/typo3-rector`) has rule +:php:`\Ssch\TYPO3Rector\TYPO314\v0\MigratePassingAnArrayOfConfigurationValuesToExtbaseAttributesRector` to +automatically migrate from the annotation syntax to the attribute syntax. + .. _extbase-validation-controller: Validation of controller arguments @@ -108,6 +156,11 @@ Validation of controller arguments deprecated. Define validators at **argument level** from TYPO3 v14. +.. versionchanged:: 14.0 + Passing a configuration array to the FileUpload attribute has been deprecated. + Configuration must be provided via named attribute arguments. See + `Migration and version compatibility (TYPO3 v13 → v14) `_. + You can also define controller argument validators: **Example:** diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/Validators/Index.rst b/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/Validators/Index.rst index 3aa7161857..9719d7ab0b 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/Validators/Index.rst +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/Validators/Index.rst @@ -19,6 +19,11 @@ along with example usage for each using PHP attributes. accept empty values as valid. If empty values should not be possible, combine these validators with the `NotEmptyValidator`. +.. versionchanged:: 14.0 + Passing a configuration array to the FileUpload attribute has been deprecated. + Configuration must be provided via named attribute arguments. See + `Migration and version compatibility (TYPO3 v13 → v14) `_. + .. contents:: Validators in Extbase .. _extbase-validator-alphanumeric: @@ -43,9 +48,10 @@ instead. .. code-block:: php - #[Validate(['validator' => 'Alphanumeric'])] + #[Validate(validator: 'Alphanumeric')] protected string $username; + .. _extbase-validator-boolean: BooleanValidator @@ -75,21 +81,27 @@ Ensure that a value is a boolean (no strict check, default behavior): .. code-block:: php - #[Validate(['validator' => 'Boolean'])] + #[Validate(validator: 'Boolean')] protected $isActive; Require that a value must be `true` (e.g. checkbox must be checked): .. code-block:: php - #[Validate(['validator' => 'Boolean', 'options' => ['is' => true]])] + #[Validate( + validator: 'Boolean', + options: ['is' => true], + )] protected bool $termsAccepted; Require that a value must be `false`: .. code-block:: php - #[Validate(['validator' => 'Boolean', 'options' => ['is' => false]])] + #[Validate( + validator: 'Boolean', + options: ['is' => false], + )] protected bool $isBlocked; .. _extbase-validator-collection: @@ -167,7 +179,7 @@ ensures a value is a valid :php:`\DateTimeInterface`. .. code-block:: php - #[Validate(['validator' => 'DateTime'])] + #[Validate(validator: 'DateTime')] protected mixed $startDate; .. _extbase-validator-disjunction: @@ -220,11 +232,9 @@ an email address using method :php:`\TYPO3\CMS\Core\Utility\GeneralUtility::vali which uses the validators defined in :ref:`$GLOBALS['TYPO3_CONF_VARS']['MAIL']['validators'] `. -It respects - .. code-block:: php - #[Validate(['validator' => 'EmailAddress'])] + #[Validate(validator: 'EmailAddress')] protected string $email; .. _extbase-validator-file-name: @@ -277,9 +287,10 @@ Checks if a value is a floating point number. .. code-block:: php - #[Validate(['validator' => 'Float'])] + #[Validate(validator: 'Float')] protected float $price; + .. _extbase-validator-image-dimensions: ImageDimensionsValidator @@ -318,14 +329,12 @@ ensures that a value is an integer. This validator is useful for validating numeric fields that must contain whole numbers, such as quantities, IDs, or counters. -#[Validate(['validator' => 'Integer'])] -protected mixed $quantity; - .. code-block:: php - #[Validate(['validator' => 'Integer'])] + #[Validate(validator: 'Integer')] protected mixed $quantity; + .. _extbase-validator-mime-type: MimeTypeValidator @@ -410,9 +419,10 @@ This validator is commonly used to enforce required fields. .. code-block:: php - #[Validate(['validator' => 'NotEmpty'])] + #[Validate(validator: 'NotEmpty')] protected string $title; + .. _extbase-validator-numberrange: NumberRangeValidator @@ -458,13 +468,14 @@ Example: Validate percentage class SettingsForm { - #[Validate([ - 'validator' => 'NumberRange', - 'options' => ['minimum' => 1, 'maximum' => 100], - ])] + #[Validate( + validator: 'NumberRange', + options: ['minimum' => 1, 'maximum' => 100], + )] protected int $percentage; } + .. _extbase-validator-regularexpression: RegularExpressionValidator @@ -513,12 +524,12 @@ Validate that a value contains only alphanumeric characters: class UserForm { - #[Validate([ - 'validator' => 'RegularExpression', - 'options' => [ - 'regularExpression' => '/^[a-z0-9]+$/i' - ] - ])] + #[Validate( + validator: 'RegularExpression', + options: [ + 'regularExpression' => '/^[a-z0-9]+$/i', + ], + )] public string $username = ''; } @@ -535,13 +546,13 @@ Validate a 5-digit postal code with a custom error message: class AddressForm { - #[Validate([ - 'validator' => 'RegularExpression', - 'options' => [ + #[Validate( + validator: 'RegularExpression', + options: [ 'regularExpression' => '/^\d{5}$/', - 'message' => 'Bitte eine gültige Postleitzahl eingeben.' - ] - ])] + 'message' => 'Bitte eine gültige Postleitzahl eingeben.', + ], + )] public string $postalCode = ''; } @@ -587,12 +598,13 @@ Options: .. code-block:: php - #[Validate([ - 'validator' => 'StringLength', - 'options' => ['minimum' => 5, 'maximum' => 50], - ])] + #[Validate( + validator: 'StringLength', + options: ['minimum' => 5, 'maximum' => 50], + )] protected string $description; + .. note:: Even if the `minimum` option is set, empty strings are accepted as valid. Combine this validator with the `NotEmptyValidator `_ @@ -608,7 +620,7 @@ validates that a mixed variable is a string. Fails for array, numbers and bools. .. code-block:: php - #[Validate(['validator' => 'String'])] + #[Validate(validator: 'String')] protected mixed $comment; .. _extbase-validator-text: @@ -625,7 +637,7 @@ Checks if the given value is a valid text (contains no HTML/XML tags). .. code-block:: php - #[Validate(['validator' => 'Text'])] + #[Validate(validator: 'Text')] protected string $comment; .. _extbase-validator-url: @@ -665,7 +677,7 @@ This example ensures that a field contains a valid external website address. class UserProfile { - #[Validate(['validator' => 'Url'])] + #[Validate(validator: 'Url')] protected string $website = ''; } @@ -687,9 +699,9 @@ You can apply multiple validators on a single property. .. code-block:: php - #[Validate(['validator' => 'NotEmpty'])] - #[Validate([ - 'validator' => 'StringLength', - 'options' => ['minimum' => 3, 'maximum' => 20], - ])] + #[Validate(validator: 'NotEmpty')] + #[Validate( + validator: 'StringLength', + options: ['minimum' => 3, 'maximum' => 20], + )] protected string $nickname; diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/Validators/_FileUploadArgument.php b/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/Validators/_FileUploadArgument.php index b8d8d77d8c..cae9e8e553 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/Validators/_FileUploadArgument.php +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/Validators/_FileUploadArgument.php @@ -7,8 +7,8 @@ class SomeDto { - #[FileUpload([ - 'validation' => [ + #[FileUpload( + validation: [ 'required' => true, 'mimeType' => [ 'allowedMimeTypes' => ['image/jpeg'], @@ -17,7 +17,7 @@ class SomeDto 'invalidExtensionMessage' => 'LLL:EXT:my_extension/...', ], ], - 'uploadFolder' => '1:/user_upload/files/', - ])] + uploadFolder: '1:/user_upload/files/', + )] protected ?FileReference $file = null; } diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/_Validation/_ValidatorWithArgumentUsage.php b/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/_Validation/_ValidatorWithArgumentUsage.php index 45fd12b3b4..2b081c30bc 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/_Validation/_ValidatorWithArgumentUsage.php +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/Validation/_Validation/_ValidatorWithArgumentUsage.php @@ -9,26 +9,26 @@ class Person extends AbstractEntity { - #[Validate([ - 'validator' => 'EmailAddress', - 'options' => [ + #[Validate( + validator: 'EmailAddress', + options: [ 'message' => 'LLL:EXT:extbase/Resources/Private/Language/locallang.xlf:validator.emailaddress.notvalid', ], - ])] + )] protected string $email = ''; - #[Validate([ - 'validator' => 'StringLength', - 'options' => [ + #[Validate( + validator: 'StringLength', + options: [ 'maximum' => 80, 'message' => 'A custom, non translatable message', ], - ])] + )] protected string $firstname = ''; - #[Validate([ - 'validator' => 'StringLength', - 'options' => ['minimum' => 2, 'maximum' => 150], - ])] + #[Validate( + validator: 'StringLength', + options: ['minimum' => 2, 'maximum' => 150], + )] protected string $lastname = ''; } diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Cascade.php b/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Cascade.php index ab3d405a64..8eb346007b 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Cascade.php +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Cascade.php @@ -13,6 +13,6 @@ final class Blog extends AbstractEntity /** * @var ObjectStorage */ - #[Cascade(['value' => 'remove'])] - public $posts; + #[Cascade(value: 'remove')] + public ObjectStorage $posts; } diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_IgnoreValidation.php b/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_IgnoreValidation.php index f51cf9ba79..f9d991ad04 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_IgnoreValidation.php +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_IgnoreValidation.php @@ -11,9 +11,10 @@ final class BlogController extends ActionController { - #[IgnoreValidation(['argumentName' => 'blog'])] - public function editAction(Blog $blog): ResponseInterface - { + public function editAction( + #[IgnoreValidation] + Blog $blog, + ): ResponseInterface { // Do something $this->view->assign('blog', $blog); return $this->htmlResponse(); diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Migration.diff b/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Migration.diff index c55f26cd04..ed614e31e9 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Migration.diff +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Migration.diff @@ -7,6 +7,6 @@ - /** - * @Extbase\Validate("NotEmpty") - */ -+ #[Extbase\Validate(['validator' => 'NotEmpty'])] ++ #[Extbase\Validate(validator: 'NotEmpty')] protected string $foo = ''; } diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Multiple.php b/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Multiple.php index 3fad5966f7..88a70f50ac 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Multiple.php +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Multiple.php @@ -11,8 +11,8 @@ class Post extends AbstractEntity { - #[Lazy()] - #[Cascade(['value' => 'remove'])] + #[Lazy] + #[Cascade(value: 'remove')] /** * @var ObjectStorage */ diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Validate.php b/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Validate.php index 00ef8d95bd..59b906c573 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Validate.php +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/_Attributes/_Validate.php @@ -9,9 +9,9 @@ class Blog extends AbstractEntity { - #[Validate([ - 'validator' => 'StringLength', - 'options' => ['maximum' => 150], - ])] + #[Validate( + validator: 'StringLength', + options: ['maximum' => 150], + )] public string $description = ''; } diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/_FileUpload/_BlogEnhanced.php b/Documentation/ExtensionArchitecture/Extbase/Reference/_FileUpload/_BlogEnhanced.php index ad9acc50bc..61a27b05f7 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/_FileUpload/_BlogEnhanced.php +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/_FileUpload/_BlogEnhanced.php @@ -13,8 +13,8 @@ class Blog extends AbstractEntity { // A single file - #[FileUpload([ - 'validation' => [ + #[FileUpload( + validation: [ 'required' => true, 'maxFiles' => 1, 'fileSize' => ['minimum' => '0K', 'maximum' => '2M'], @@ -26,14 +26,14 @@ class Blog extends AbstractEntity ], 'imageDimensions' => ['maxWidth' => 4096, 'maxHeight' => 4096], ], - 'uploadFolder' => '1:/user_upload/extbase_single_file/', - 'addRandomSuffix' => true, - 'duplicationBehavior' => DuplicationBehavior::RENAME, - ])] + uploadFolder: '1:/user_upload/extbase_single_file/', + addRandomSuffix: true, + duplicationBehavior: DuplicationBehavior::RENAME, + )] protected ?FileReference $singleFile = null; - #[FileUpload([ - 'validation' => [ + #[FileUpload( + validation: [ 'required' => true, 'fileSize' => ['minimum' => '0K', 'maximum' => '2M'], 'mimeType' => [ @@ -43,30 +43,24 @@ class Blog extends AbstractEntity 'invalidExtensionMessage' => 'LLL:EXT:my_extension/...', ], ], - 'uploadFolder' => '1:/user_upload/extbase_multiple_files/', - ])] - + uploadFolder: '1:/user_upload/extbase_multiple_files/', + )] /** * A collection of files. * @var ObjectStorage */ protected ObjectStorage $multipleFiles; - // When using ObjectStorages, it is vital to initialize these. public function __construct() { $this->multipleFiles = new ObjectStorage(); } - /** - * Called again with initialize object, as fetching an entity from the DB does not use the constructor - */ public function initializeObject(): void { $this->multipleFiles = $this->multipleFiles ?? new ObjectStorage(); } - // Typical getters public function getSingleFile(): ?FileReference { return $this->singleFile; @@ -80,7 +74,6 @@ public function getMultipleFiles(): ObjectStorage return $this->multipleFiles; } - // Typical setters public function setSingleFile(?FileReference $singleFile): void { $this->singleFile = $singleFile; diff --git a/Documentation/ExtensionArchitecture/Extbase/Reference/_FileUpload/_BlogExcerpt.php b/Documentation/ExtensionArchitecture/Extbase/Reference/_FileUpload/_BlogExcerpt.php index 5f457490b7..835a73bcce 100644 --- a/Documentation/ExtensionArchitecture/Extbase/Reference/_FileUpload/_BlogExcerpt.php +++ b/Documentation/ExtensionArchitecture/Extbase/Reference/_FileUpload/_BlogExcerpt.php @@ -10,8 +10,8 @@ class Blog extends AbstractEntity { - #[FileUpload([ - 'validation' => [ + #[FileUpload( + validation: [ 'required' => true, 'maxFiles' => 1, 'fileSize' => ['minimum' => '0K', 'maximum' => '2M'], @@ -21,10 +21,12 @@ class Blog extends AbstractEntity 'notAllowedMessage' => 'LLL:EXT:my_extension/...', 'invalidExtensionMessage' => 'LLL:EXT:my_extension/...', ], - 'fileExtension' => ['allowedFileExtensions' => ['jpg', 'jpeg', 'png']], + 'fileExtension' => [ + 'allowedFileExtensions' => ['jpg', 'jpeg', 'png'], + ], ], - 'uploadFolder' => '1:/user_upload/files/', - ])] + uploadFolder: '1:/user_upload/files/', + )] protected ?FileReference $file = null; // getters and setters like usual