[TASK] Unify NULL default value handling 08/26408/9
authorAlexander Stehlik <alexander.stehlik@googlemail.com>
Mon, 13 Jan 2014 10:20:06 +0000 (11:20 +0100)
committerPhilipp Gampe <philipp.gampe@typo3.org>
Tue, 18 Mar 2014 23:41:03 +0000 (00:41 +0100)
If a field is configured to allow NULL values ("eval" is set to "null")
and the default value in the TCA is explicitly set to NULL the value
will not be converted to a string.

Additionally the mode setting "useOrOverridePlaceholder" will not have
any influence any more on the default value when creating new records.

Resolves: #54412
Releases: 6.2
Documentation: #56584
Change-Id: Ica43a1af33e6f86dd042b66781acc0e9cd904cf9
Reviewed-on: https://review.typo3.org/26408
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Wouter Wolters
Reviewed-by: Oliver Hader
Reviewed-by: Ernesto Baschny
Reviewed-by: Stefan Neufeind
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
typo3/sysext/backend/Classes/Form/DataPreprocessor.php
typo3/sysext/backend/Classes/Form/FormEngine.php
typo3/sysext/core/Configuration/TCA/sys_file_reference.php

index 1a9fc1b..9527fbc 100644 (file)
@@ -261,8 +261,16 @@ class DataPreprocessor {
                        // Set $data variable for the field, either inputted value from $row - or if not found, the default value as defined in the "config" array
                        if (isset($row[$field])) {
                                $data = (string)$row[$field];
-                       } elseif (array_key_exists($field, $row) && !empty($fieldConfig['config']['eval']) && GeneralUtility::inList($fieldConfig['config']['eval'], 'null')) {
-                               $data = NULL;
+                       } elseif (!empty($fieldConfig['config']['eval']) && GeneralUtility::inList($fieldConfig['config']['eval'], 'null')) {
+                               // Field exists but is set to NULL
+                               if (array_key_exists($field, $row)) {
+                                       $data = NULL;
+                               // Only use NULL if default value was explicitly set to be backward compatible.
+                               } elseif (array_key_exists('default', $fieldConfig['config']) && $fieldConfig['config']['default'] === NULL) {
+                                       $data = NULL;
+                               } else {
+                                       $data = (string)$fieldConfig['config']['default'];
+                               }
                        } else {
                                $data = (string)$fieldConfig['config']['default'];
                        }
index 424af3c..329d450 100644 (file)
@@ -1155,10 +1155,7 @@ class FormEngine {
                                        if (isset($PA['fieldConf']['config']['mode']) && $PA['fieldConf']['config']['mode'] == 'useOrOverridePlaceholder') {
                                                $placeholder = $this->getPlaceholderValue($table, $field, $PA['fieldConf']['config'], $row);
                                                $onChange = 'typo3form.fieldTogglePlaceholder(' . GeneralUtility::quoteJSvalue($PA['itemFormElName']) . ', !this.checked)';
-
-
-                                               $isNull = ($PA['itemFormElValue'] === NULL);
-                                               $checked = (($isNull || $this->isNewRecord($table, $row)) ? '' : ' checked="checked"');
+                                               $checked = $PA['itemFormElValue'] === NULL ? '' : ' checked="checked"';
 
                                                $this->additionalJS_post[] = 'typo3form.fieldTogglePlaceholder('
                                                        . GeneralUtility::quoteJSvalue($PA['itemFormElName']) . ', ' . ($checked ? 'false' : 'true') . ');';
index e50e421..a64c4ec 100644 (file)
@@ -161,6 +161,7 @@ return array(
                                'eval' => 'null',
                                'placeholder' => '__row|uid_local|metadata|title',
                                'mode' => 'useOrOverridePlaceholder',
+                               'default' => NULL,
                        )
                ),
                'link' => array(
@@ -199,6 +200,7 @@ return array(
                                'eval' => 'null',
                                'placeholder' => '__row|uid_local|metadata|description',
                                'mode' => 'useOrOverridePlaceholder',
+                               'default' => NULL,
                        )
                ),
                'alternative' => array(
@@ -211,6 +213,7 @@ return array(
                                'eval' => 'null',
                                'placeholder' => '__row|uid_local|metadata|alternative',
                                'mode' => 'useOrOverridePlaceholder',
+                               'default' => NULL,
                        ),
                ),
        ),