Issue Feature Closed

#108227Allow #[IgnoreValidation] and #[Validate] attributes at controller action method parameters

Elias Häußler 11/20/25, 19:19 updated 12/02/25, 11:48

Description

Both #[IgnoreValidation] and #[Validate] can be used at controller actions to configure the validation behavior for either (1) the complete method or (2) a single parameter. This works fine for (1). However, using these attributes in context of (2) raises some concerns concerning (a) duplication of parameter names, (b) validation of the actual existence of a configured parameter and © unnecessary complexity regarding reflection-based handling of these parameters.

When the attributes were originally implemented as Doctrine annotations, the only possible way to implement behavior (2) was to add the appropriate annotation to the method-related annotation. Since #107229, annotations are no longer used in Extbase, and PHP attributes are the only left successor in this area. Since PHP attributes support placement at specific method parameters, the existing attributes can be safely rewritten to be placed (A) at a specific method and (B) at a specific method parameter.

This patch implements this behavior: The capabilities of the existing attributes are expanded to allow placement at method parameters as well. The previous behavior (defining validation-related behavior at method level using the existing attribute properties) is now deprecated and will be removed with TYPO3 v15.

Developers can easily migrate their implementations by moving parameter-related attributes next to the method parameters instead of the related method.

Before:

final class FooController extends ActionController
{
    #[IgnoreValidation(argumentName: 'something')]
    public function barAction(string $something): ResponseInterface
    {
        // Do something...
    }

    #[Validate(validator: 'NotEmpty', param: 'anythingNotEmpty')]
    public function bazAction(string $anythingNotEmpty): ResponseInterface
    {
        // Do something...
    }
}

After:

final class FooController extends ActionController
{
    public function barAction(
        #[IgnoreValidation]
        string $something,
    ): ResponseInterface {
        // Do something...
    }

    public function bazAction(
        #[Validate(validator: 'NotEmpty')]
        string $anythingNotEmpty,
    ): ResponseInterface {
        // Do something...
    }
}

Reviews 4