[FEATURE] Integrate possibility to determine NULL values in TypoScript
authorOliver Hader <oliver@typo3.org>
Tue, 20 Nov 2012 20:14:45 +0000 (21:14 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Tue, 20 Nov 2012 23:39:26 +0000 (00:39 +0100)
Currently there's no possibility to handle NULL values in
TypoScript. This is related to the feature "Add possibility
to store NULL values (#41773)".

Thus, two new elements are integrated:
* (stdWrap).ifNull -> string/stdWrap
* (stdWrap).if.isNull -> stdWrap

Change-Id: I77a29341c66edaf3bef14de33f65c702fbbb9fbd
Resolves: #43133
Releases: 6.0
Reviewed-on: http://review.typo3.org/16637
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index 092ff84..9c7cdb1 100644 (file)
@@ -82,6 +82,8 @@ class ContentObjectRenderer {
                'override.' => 'array',
                'preIfEmptyListNum' => 'listNum',
                'preIfEmptyListNum.' => 'array',
+               'ifNull' => 'string',
+               'ifNull.' => 'array',
                'ifEmpty' => 'string',
                'ifEmpty.' => 'array',
                'ifBlank' => 'string',
@@ -2233,6 +2235,21 @@ class ContentObjectRenderer {
                return $content;
        }
 
+       /**
+        * ifNull
+        * Will set content to a replacement value in case the value of content is NULL
+        *
+        * @param string|NULL $content Input value undergoing processing in this function.
+        * @param array $conf stdWrap properties for ifNull.
+        * @return string|NULL The processed input value
+        */
+       public function stdWrap_ifNull($content = '', $conf = array()) {
+               if ($content === NULL) {
+                       $content = $conf['ifNull'];
+               }
+               return $content;
+       }
+
        /**
         * ifEmpty
         * Will set content to a replacement value in case the trimmed value of content returns FALSE
@@ -3419,6 +3436,12 @@ class ContentObjectRenderer {
                        return $conf['directReturn'] ? 1 : 0;
                }
                $flag = TRUE;
+               if (isset($conf['isNull.'])) {
+                       $isNull = $this->stdWrap('', $conf['isNull.']);
+                       if ($isNull !== NULL) {
+                               $flag = 0;
+                       }
+               }
                if (isset($conf['isTrue']) || isset($conf['isTrue.'])) {
                        $isTrue = isset($conf['isTrue.']) ? trim($this->stdWrap($conf['isTrue'], $conf['isTrue.'])) : trim($conf['isTrue']);
                        if (!$isTrue) {
index 2ee4972..48a3f8b 100644 (file)
@@ -1063,6 +1063,39 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->assertEquals('01-09-2012', $result);
        }
 
+       /**
+        * @param string|NULL $content
+        * @param array $configuration
+        * @param string $expected
+        * @dataProvider stdWrap_ifNullDeterminesNullValuesDataProvider
+        * @test
+        */
+       public function stdWrap_ifNullDeterminesNullValues($content, array $configuration, $expected) {
+               $result = $this->cObj->stdWrap_ifNull($content, $configuration);
+               $this->assertEquals($expected, $result);
+       }
+
+       /**
+        * @return array
+        */
+       public function stdWrap_ifNullDeterminesNullValuesDataProvider() {
+               return array(
+                       'null value' => array(
+                               NULL,
+                               array(
+                                       'ifNull' => '1',
+                               ),
+                               '1',
+                       ),
+                       'zero value' => array(
+                               '0',
+                               array(
+                                       'ifNull' => '1',
+                               ),
+                               '0',
+                       ),
+               );
+       }
 }
 
 ?>
\ No newline at end of file