Bug #70017
closedDomain object validation ignored, when object has property of the same type
100%
Description
When an object has a property, that is of the same type as the current object (e.g. if object can have parent objects of the same type), domain object validation seems to be ignored completely.
Description in short:
Domain model is as following (simplyfied):
class Testmodel extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity { /** * A required field * * @var string * @validate NotEmpty */ protected $field1 = ''; /** * parent (should only hold one object) * * @var \Vendor\Extensionkey\Domain\Model\Testmodel */ protected $parent = NULL; ...getters and setters for field1 and $parent }
In an Extbase extension, I create a plugin which shows a form that should create a new object of type "Testmodel" on form submission.
Submitting an empty form results in the following:
TYPO3 6.2: The validator for $field1 is processed and the object is not created (createAction not processed)
TYPO3 Master: The validator for field1 is processes and the object gets created (createAction processed)
I created a little demo extension, which demonstrates the problem.
Link: https://github.com/derhansen/test_extension
In plugin "Form1", domain object validations works. For plugin "Form2" the domain object validation is ignored and empty forms can be submitted and gets saved.
It took me some hours of debugging to find out, that the @var \Vendor\Extensionkey\Domain\Model\Testmodel for $parent is the reason for this unexpected behaviour.
Changing the @var annotation to @var int or \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\Extensionkey\Domain\Model\Testmodel> for the $parent property seems to resolve the problem (getters and setters remain as they are).
Really strange problem, since empty forms can be saved to the database and the domain model validation is ignored completely.