[BUGFIX] Property of alternative model implementation not found 27/33327/2
authorOliver Hader <oliver@typo3.org>
Thu, 31 Jul 2014 13:17:38 +0000 (15:17 +0200)
committerMarkus Klein <klein.t3@reelworx.at>
Wed, 15 Oct 2014 21:19:30 +0000 (23:19 +0200)
The PersistentObjectConverter is mapping submitted data to a
given target domain model. If a class gets overloaded with
config.tx_extbase.objects, this information is not forwarded
to the ReflectionService. That's why properties in alternative
implementations cannot be determined.

Resolves: #49803
Releases: master, 6.2, 6.1
Change-Id: Ia4ec3a6c6f5bc6c07717a4956ab12e3e779c3c5a
Reviewed-on: http://review.typo3.org/33327
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/extbase/Classes/Object/Container/Container.php
typo3/sysext/extbase/Classes/Property/TypeConverter/ObjectConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/PersistentObjectConverter.php

index e6f99c9..432ecb0 100644 (file)
@@ -288,7 +288,7 @@ class Container implements \TYPO3\CMS\Core\SingletonInterface {
         * @param string $className Base class name to evaluate
         * @return string Final class name to instantiate with "new [classname]
         */
-       protected function getImplementationClassName($className) {
+       public function getImplementationClassName($className) {
                if (isset($this->alternativeImplementation[$className])) {
                        $className = $this->alternativeImplementation[$className];
                }
index a56044f..eb78ab9 100644 (file)
@@ -59,6 +59,12 @@ class ObjectConverter extends AbstractTypeConverter implements \TYPO3\CMS\Core\S
        protected $objectManager;
 
        /**
+        * @var \TYPO3\CMS\Extbase\Object\Container\Container
+        * @inject
+        */
+       protected $objectContainer;
+
+       /**
         * @var \TYPO3\CMS\Extbase\Reflection\ReflectionService
         * @inject
         */
@@ -103,20 +109,21 @@ class ObjectConverter extends AbstractTypeConverter implements \TYPO3\CMS\Core\S
                        return $configuredTargetType;
                }
 
-               if ($this->reflectionService->hasMethod($targetType, \TYPO3\CMS\Extbase\Reflection\ObjectAccess::buildSetterMethodName($propertyName))) {
-                       $methodParameters = $this->reflectionService->getMethodParameters($targetType, \TYPO3\CMS\Extbase\Reflection\ObjectAccess::buildSetterMethodName($propertyName));
+               $specificTargetType = $this->objectContainer->getImplementationClassName($targetType);
+               if ($this->reflectionService->hasMethod($specificTargetType, \TYPO3\CMS\Extbase\Reflection\ObjectAccess::buildSetterMethodName($propertyName))) {
+                       $methodParameters = $this->reflectionService->getMethodParameters($specificTargetType, \TYPO3\CMS\Extbase\Reflection\ObjectAccess::buildSetterMethodName($propertyName));
                        $methodParameter = current($methodParameters);
                        if (!isset($methodParameter['type'])) {
-                               throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException('Setter for property "' . $propertyName . '" had no type hint or documentation in target object of type "' . $targetType . '".', 1303379158);
+                               throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException('Setter for property "' . $propertyName . '" had no type hint or documentation in target object of type "' . $specificTargetType . '".', 1303379158);
                        } else {
                                return $methodParameter['type'];
                        }
                } else {
-                       $methodParameters = $this->reflectionService->getMethodParameters($targetType, '__construct');
+                       $methodParameters = $this->reflectionService->getMethodParameters($specificTargetType, '__construct');
                        if (isset($methodParameters[$propertyName]) && isset($methodParameters[$propertyName]['type'])) {
                                return $methodParameters[$propertyName]['type'];
                        } else {
-                               throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException('Property "' . $propertyName . '" had no setter or constructor argument in target object of type "' . $targetType . '".', 1303379126);
+                               throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException('Property "' . $propertyName . '" had no setter or constructor argument in target object of type "' . $specificTargetType . '".', 1303379126);
                        }
                }
        }
@@ -199,8 +206,9 @@ class ObjectConverter extends AbstractTypeConverter implements \TYPO3\CMS\Core\S
         * @throws \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException if a required constructor argument is missing
         */
        protected function buildObject(array &$possibleConstructorArgumentValues, $objectType) {
-               if ($this->reflectionService->hasMethod($objectType, '__construct')) {
-                       $constructorSignature = $this->reflectionService->getMethodParameters($objectType, '__construct');
+               $specificObjectType = $this->objectContainer->getImplementationClassName($objectType);
+               if ($this->reflectionService->hasMethod($specificObjectType, '__construct')) {
+                       $constructorSignature = $this->reflectionService->getMethodParameters($specificObjectType, '__construct');
                        $constructorArguments = array();
                        foreach ($constructorSignature as $constructorArgumentName => $constructorArgumentInformation) {
                                if (array_key_exists($constructorArgumentName, $possibleConstructorArgumentValues)) {
index 56a8f1e..93e1175 100644 (file)
@@ -109,9 +109,10 @@ class PersistentObjectConverter extends ObjectConverter {
                        return $configuredTargetType;
                }
 
-               $schema = $this->reflectionService->getClassSchema($targetType);
+               $specificTargetType = $this->objectContainer->getImplementationClassName($targetType);
+               $schema = $this->reflectionService->getClassSchema($specificTargetType);
                if (!$schema->hasProperty($propertyName)) {
-                       throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException('Property "' . $propertyName . '" was not found in target object of type "' . $targetType . '".', 1297978366);
+                       throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException('Property "' . $propertyName . '" was not found in target object of type "' . $specificTargetType . '".', 1297978366);
                }
                $propertyInformation = $schema->getProperty($propertyName);
                return $propertyInformation['type'] . ($propertyInformation['elementType'] !== NULL ? '<' . $propertyInformation['elementType'] . '>' : '');