[BUGFIX] Respect wildcard in PropertyConfiguration shouldMap()
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Sun, 10 Feb 2013 10:39:14 +0000 (11:39 +0100)
committerAndreas Wolf <andreas.wolf@typo3.org>
Sun, 10 Feb 2013 13:08:54 +0000 (14:08 +0100)
Using 'name.*' in property mapping configuration did not work for
fields added on the client, because shouldMap() would reject those
fields before the configuration was even checked.

This patch is a backport from Flow.

Fixes: #43928
Releases: 6.1, 6.0
Change-Id: I7fb71f705f242160700e8c082373f547d9cf72b5
Reviewed-on: https://review.typo3.org/18177
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Andreas Wolf
Tested-by: Andreas Wolf
typo3/sysext/extbase/Classes/Property/PropertyMappingConfiguration.php
typo3/sysext/extbase/Tests/Unit/Property/PropertyMappingConfigurationTest.php

index 19aa396..e42a62c 100644 (file)
@@ -29,6 +29,11 @@ namespace TYPO3\CMS\Extbase\Property;
 class PropertyMappingConfiguration implements \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface {
 
        /**
+        * Placeholder in property paths for multi-valued types
+        */
+       const PROPERTY_PATH_PLACEHOLDER = '*';
+
+       /**
         * multi-dimensional array which stores type-converter specific configuration:
         * 1. Dimension: Fully qualified class name of the type converter
         * 2. Dimension: Configuration Key
@@ -99,14 +104,13 @@ class PropertyMappingConfiguration implements \TYPO3\CMS\Extbase\Property\Proper
        /**
         * The behavior is as follows:
         *
-        * - if a property has been explicitely forbidden using allowAllPropertiesExcept(...), it is directly rejected
+        * - if a property has been explicitly forbidden using allowAllPropertiesExcept(...), it is directly rejected
         * - if a property has been allowed using allowProperties(...), it is directly allowed.
         * - if allowAllProperties* has been called, we allow unknown properties
         * - else, return FALSE.
         *
         * @param string $propertyName
         * @return boolean TRUE if the given propertyName should be mapped, FALSE otherwise.
-        * @todo : extend to enable whitelisting / blacklisting of properties.
         * @api
         */
        public function shouldMap($propertyName) {
@@ -116,6 +120,9 @@ class PropertyMappingConfiguration implements \TYPO3\CMS\Extbase\Property\Proper
                if (isset($this->propertiesToBeMapped[$propertyName])) {
                        return TRUE;
                }
+               if (isset($this->subConfigurationForProperty[self::PROPERTY_PATH_PLACEHOLDER])) {
+                       return TRUE;
+               }
                return $this->mapUnknownProperties;
        }
 
index ff53200..54fad74 100644 (file)
@@ -154,6 +154,15 @@ class PropertyMappingConfigurationTest extends \TYPO3\CMS\Extbase\Tests\Unit\Bas
                $this->assertEquals('k1a', $this->propertyMappingConfiguration->getTargetPropertyName('k1'));
                $this->assertEquals('k2', $this->propertyMappingConfiguration->getTargetPropertyName('k2'));
        }
+
+       /**
+        * @test
+        */
+       public function shouldMapAllowsArbitraryPropertiesWhenConfiguredWithAsterisk() {
+               $this->propertyMappingConfiguration->forProperty('items.*')->setTypeConverterOptions('someConverter', array('k1' => 'v1'));
+               $configuration = $this->propertyMappingConfiguration->forProperty('items');
+               $this->assertTrue($configuration->shouldMap(uniqid()));
+       }
 }
 
 ?>
\ No newline at end of file