#78607ValidationResults viewhelper for-attribute object handling
Description
When you have a partial fluid template in your extbase / fluid extension for outputting the validation results of an object creation or updating, there seems to be a strange / unexpected behaviour to me, which can lead to a pitfall especially for developers new to extbase and fluid. The following example of passing the object {user} in e.g. EXT:somextension/Resources/Private/Templates/User/Edit.html and EXT:somextension/Resources/Private/Templates/User/New.html works fine. This seems strange to me as the object was assigned to both templates as a lowercase “user” and not as upper camelcase “User” via $this->view->assign(‘user’, $user):
...
<f:render partial="FormErrors.html" arguments="{object : User}" />
...
Whereas the partial EXT:somextension/Resources/Private/Partials/FormErrors.html looks like this:
...
<f:form.validationResults for="{object}">
...
</f:form.validationResults>
...
When I change the line in the template EXT:somextension/Resources/Private/Templates/User/Edit.html to the obviously correct way of spelling object “user”, it throws an uncaught TYPO3 Exception #1: PHP Warning: Illegal offset type in isset or empty in ../typo3/sysext/extbase/Classes/Error/Result.php line 214:
...
<f:render partial="FormErrors.html" arguments="{object : user}" />
...
When I change the line in the template EXT:somextension/Resources/Private/Templates/User/Edit.html to the obviously correct way of spelling object “user”, it still works fine though:
...
<f:render partial="FormErrors.html" arguments="{object : user}" />
...
I think this is a kind of unexpected / irrational behaviour and should be corrected, as it can lead to unnecessary confusion and frustration for beginner developers in extbase and fluid.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
History 3
-
Matthias Krappitz commented <span data-processor="relativetime" data-value="2016-11-08T18:52:31+00:00" > 11/08/16, 18:52 </span>
-
Benni Mack changed target version <span data-processor="relativetime" data-value="2019-04-17T23:40:59+00:00" > 04/17/19, 23:40 </span>
-
Georg Ringer commented and changed status
NewClosed <span data-processor="relativetime" data-value="2026-09-16T19:23:16+00:00" > 09/16/26, 19:23 </span>(Created with AI support)
This can be closed. The behaviour reported in 2016 no longer exists in this
form. Verified on current main:for= receives result ---------------------- ------------------------------------- an Extbase object renders nothing at all an undefined variable renders all validation results a correct string correct results
There is no PHP warning any more.
Result::forProperty()is typed?string,
and Fluid casts the value before it ever reachesResult. The cast succeeds
becauseAbstractDomainObject::__toString()returns
@static::class . ‘:’ . $this->uid@, which makes every domain object implicitly
@Stringable@. Theforargument therefore becomes a string such as
@Vendor\Model\User:12@ – a syntactically valid but non-existent property path,
and an unknown path yields an empty result object. Hence no error, but nothing
rendered either.The second observation (an undefined variable showing all errors) cannot be
fixed in the ViewHelper.ViewHelperInvokerchecks arguments withisset(),
andisset(null)isfalse, so an argument that evaluates tonullis
indistinguishable from one that was never given and falls back to the default
value''. An emptyformeans “all results” by design.Making unknown property paths raise an error is not possible either.
@Result::forProperty()@ is the very same API the validators use to build the
result tree (CollectionValidator,AbstractGenericObjectValidator), so it
has to create sub-results on demand. And on the reading side, “there is no
sub-result for this path” cannot be told apart from “this property has no
errors” – which is the normal state of every freshly rendered form. Throwing
there would break every valid form.What did improve in the meantime: #73717 removed the most frequent real-world
cause of “@f:form.validationResults@ renders nothing” – property paths of
collection elements that could never match, because validation results of an
@ObjectStorage@ were keyed byspl_object_hash()while the form fields address
the same element by its position.additionally the following issues will be solved #85070 & #73717
TYPO3 version 6.2.28