Bug #73717

validation results for child properties per property

Added by Pascal Dürsteler over 5 years ago. Updated about 2 years ago.

Status:
New
Priority:
Must have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2016-02-27
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
7
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

When you have a model "pizza" with a property "toppings" being an object storage containing multiple "topping" objects, it is not possible to display validation results for each toppings' properties.

According to several sources (e.g. #70634), the way of building a form for a pizza with multiple toppings would look like this in fluid:

<f:for each="{pizza.toppings}" as="topping" iteration="i">
    <f:form.textfield property="toppings.{i.index}.title" />
    <!-- ... -->
</f:for>

However, validation results fetched via f:form.validationResults don't have the same index. Outputting validationResults.flattenedErrors yields something like this:

array(
    pizza.toppings.0000000027a19482000000016f491783.title => array
)

As far as I know for now, only by using functionality provided by the core, it is not possible to display errors for said properties. If there is a way, I'd be happy to see a clean, nice, and simple way. Otherwise, I consider this a bug or a missing feature, as I feel a framework should provide such functionality.

Assigning this to Category: Fluid for now, as it mainly depends on f:form.validationResults. Adding Claus as watcher as he provided a very explanative answer on #70634, which is marginally related to this issue.


Related issues

Related to TYPO3 Core - Feature #70634: Proper view helper for generating nested / child recordsRejected2015-10-12

Actions
#1

Updated by Claus Due over 5 years ago

  • Category changed from Fluid to Extbase

Moved to Extbase as it directly relates to the validation, more specifically how a validator validates collections which involves iterating over child objects and allowing key() on ObjectStorage to deliver the index. AFAICS there are some ways around this:

1) Use toArray() on ObjectStorage before validating - this is as far as I am aware quite safe to do.
2) Check in GenericObjectValidator if we're validating an ObjectStorage, configure the collection validator to manually increment keys instead of assigning the key variable in the foreach loop.
3) Make CollectionValidator detect if collection is specifically an ObjectStorage then manually increment keys while validating.

Looks like the first option would be better. Should probably not be applied on LTS since it would change for example the key value of all f:for's used on validation results, as well as manual access to specific objects' validation results in things like controllers or custom parent object validators. Although it's a small change it has some far reaching impact.

#2

Updated by Pascal Dürsteler over 5 years ago

Thanks Claus for your response.

I've solved it with a view helper which returns the property results I need.

public function render($validationResults, $index, $property) {
        $correctResults = array_shift(array_slice($validationResults->getSubResults(), $index, 1));
        if ($correctResults) {
            $propertyResults = $correctResults->getSubResults()[$property];
            $this->templateVariableContainer->add('subPropertyValidationResults', $propertyResults);
            $output = $this->renderChildren();
            $this->templateVariableContainer->remove('subPropertyValidationResults');
            return $output;
        }     
}

But my point stands: IMHO this should be easily done without that much effort, and provided by the framework.

#3

Updated by Sven Burkert over 4 years ago

Is there a solution for this now?
I've tried the viewhelper, but with no success.
And I don't understand the three points of Claus Due.

#4

Updated by Mathias Brodala about 2 years ago

Did you guys try the key="foo" argument of the f:for viewhelper? It works fine with that one.

Also available in: Atom PDF