Bug #75231

PropertyMapper fails for Demand-Object like objects

Added by Bernhard Kraft about 3 years ago. Updated 2 months ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Extbase
Start date:
2016-03-22
Due date:
% Done:

0%

TYPO3 Version:
8
PHP Version:
5.6
Tags:
Complexity:
hard
Is Regression:
No
Sprint Focus:

Description

When creating a Dto which is used for Demand-Object like tasks the property mapper will fail to map sub-properties within an "ObjectStorage". Think of a demandObject which gets passed to a controller as argument.

The demandObject itself should not get persisted, but the properties it relates to can be UIDs of some already persisted domain objects. The DemandObject (DTO) could look like:

<?php
namespace Myspace\MyExt\Domain\Dto;

/**
 * A demand object 
 */
class DemandProduct {

    /**
     * The country in which the product must be located
     *
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Myspace\MyExt\Domain\Model\Country>
     */
    protected $country = NULL;

    /* ... getters and setters ... */

}

Now when you have a controller which gets passed such an object the property mapper will fail for a request like:

index.php?id=123&tx_myext_productlist[demand][country][]=12&tx_myext_productlist[demand][country][]=34

The facts:

1. The PropertyMapper will choose the "ObjectConverter" type converter for generating the "DemandProduct" class as the "DemandProduct" class does not inherit from an persistable domain model class "\TYPO3\CMS\Extbase\DomainObject\AbstractEntity"

2. The PropertyMapper would correctly choose "ObjectStorageConverter" for converting the list of passed "country" arguments when "country.*" gets set as allowed (or the value is posted from within a f:fluid form and has correct trusted properties parameter)

3. The PropertyMapper would correctly choose "PeristentObjectConverter" for the "Country" Domain model objects as the inherit from "AbstractEntity".

The reason for failing:

The reason this will fail is that the "ObjectConverter" of the base-object (DemandProduct) does not pass the "full" property types "ObjectStorage<DomainModel>" to the ObjectStorageConverter but only the base class "ObjectStorage".

To get a clue on this compare the "getTypeOfChildProperty" method from both: The "ObjectConverter" and the "PeristentObjectConverter":

https://git.typo3.org/Packages/TYPO3.CMS.git/blob/HEAD:/typo3/sysext/extbase/Classes/Property/TypeConverter/ObjectConverter.php#l116
https://git.typo3.org/Packages/TYPO3.CMS.git/blob/HEAD:/typo3/sysext/extbase/Classes/Property/TypeConverter/PersistentObjectConverter.php#l115

While the "ObjectConverter" variant of "getTypeOfChildProperty()" inspects the method nacelle the "PersistentObjectConverter" variant of the method inspects the DTO property.

The property definition annotation contains the full sub-property type: "\TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Myspace\MyExt\Domain\Model\Country>
" while the setter method will most surely only contain the "direct" type of the passed variable: "\TYPO3\CMS\Extbase\Persistence\ObjectStorage" (as the <> notation is not valid for PHP itself)

To solve this issue there should be a configuration option for "ObjectConverter" whether the setter-method-definition of the property-definition for a mapped property should get inspected.

Another solution would be to provide a "PropertyBasedObjectConverter" which behaves like the ObjectConverter in every case except for the mentioned "getTypeOfChildProperty()" method which is taken from the "PersistentObjectConverter".


Related issues

Related to TYPO3 Core - Bug #61628: PropertyMappingConfiguration for ObjectStorages / Arrays New 2014-09-16

History

#1 Updated by Benni Mack 2 months ago

  • Target version changed from next-patchlevel to Candidate for patchlevel

Also available in: Atom PDF