vog
vog

Reputation: 25597

How to validate multiple Typo3 action parameters in combination?

The Typo3 documentation describes @Validate annotations which can be used to validate parameters for a single controller action:

However, it is only described how to add a custom validator for a single parameter. It is possible to add multiple validation annotations, but then again each of them can validate just a single parameter, not multiple parameters in combination.

First question: It is possible to add a validator which checks multiple parameters, or even all parameters, of a specific controller action?

Of course the obvious workaround is to combine multiple arguments in a single argument, using e.g. an array or an object. But this is especially annoying if the arguments themselves are already (independent) model objects.

Second question: If the answer to the first question is "it's impossible", what is the recommended way to combine the arguments of a controller action?

(e.g.: Should one use an array? That seems to be not preferred in Typo3 due to the lack of type safety and other features. Should one create a class? But which kind of class would that be? A Utility class? A Model class? But that model class would then need suppressed persistence? This seems to be all messy.)

I'm using version 9.5 of Typo3, but if things are different in version 10, that would be interesting as well.

Upvotes: 0

Views: 635

Answers (1)

M Klein
M Klein

Reputation: 563

To the best of my knowledge I suggest using a data transfer object (DTO) for this purpose. If your models have to be validated in combination, but do not belong to any other entity, combining them in a DTO is probably the best way to go. Consequently the validation logic is then clustered in a single validator.

See also this blog post about DTOs: https://usetypo3.com/dtos-in-extbase.html

Upvotes: 2

Related Questions