[FEATURE] Allow nested array access in getData type field 40/36040/5
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Fri, 16 Jan 2015 10:43:43 +0000 (11:43 +0100)
committerPhilipp Gampe <philipp.gampe@typo3.org>
Sat, 17 Jan 2015 20:17:00 +0000 (21:17 +0100)
In order to make Typoscript more consistent we now allow to use nested
access to arrays for the datatype "field".

Resolves: #20767
Releases: master
Change-Id: I801054175c94151b7799300c575e34a1a29c7086
Reviewed-on: http://review.typo3.org/36040
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Feature-20767-getDataByNestedKey.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-20767-getDataByNestedKey.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-20767-getDataByNestedKey.rst
new file mode 100644 (file)
index 0000000..ed0721a
--- /dev/null
@@ -0,0 +1,23 @@
+===============================================================
+Feature: #20767 - Allow nested array access on getData of field
+===============================================================
+
+Description
+===========
+
+Right now the ``getData`` type in TS only allows to access nested arrays in types GPVar and TSFE.
+Now the same is allowed for ``field`` too.
+
+If the field value is :php:`array('somekey' => array('level1' => array('level2' => 'somevalue')));`, you can get the
+``somevalue`` by configuring the following `TypoScript`.
+
+.. code-block:: typoscript
+       10 = TEXT
+       10.data = field:fieldname|level1|level2
+
+
+Impact
+======
+
+You can now access nested keys via getData ``field:``. Nested keys are not available with the default set of
+content objects, however just content objects and ``USER`` object may return such a field structure.
index fd61468..c76d1fe 100644 (file)
@@ -5489,7 +5489,7 @@ class ContentObjectRenderer {
                                                $retVal = $this->getEnvironmentVariable($key);
                                                break;
                                        case 'field':
-                                               $retVal = $fieldArray[$key];
+                                               $retVal = $this->getGlobal($key, $fieldArray);
                                                break;
                                        case 'file':
                                                $retVal = $this->getFileDataKey($key);
index 7ee5c0a..1851daa 100644 (file)
@@ -1794,7 +1794,7 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        }
 
        /**
-        * Checks if getData() works with type "getindpenv"
+        * Checks if getData() works with type "field"
         *
         * @test
         */
@@ -1807,6 +1807,20 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        }
 
        /**
+        * Checks if getData() works with type "field" of the field content
+        * is multi-dimensional (e.g. an array)
+        *
+        * @test
+        */
+       public function getDataWithTypeFieldAndFieldIsMultiDimensional() {
+               $key = 'somekey|level1|level2';
+               $value = 'somevalue';
+               $field = array('somekey' => array('level1' => array('level2' => 'somevalue')));
+
+               $this->assertEquals($value, $this->subject->getData('field:' . $key, $field));
+       }
+
+       /**
         * Basic check if getData gets the uid of a file object
         *
         * @test