[BUGFIX] Create workspace label placeholder that matches field conditions 35/22935/11
authorSascha Egerer <sascha.egerer@dkd.de>
Wed, 7 Aug 2013 17:10:04 +0000 (19:10 +0200)
committerSascha Egerer <sascha@sascha-egerer.de>
Wed, 2 Jul 2014 07:25:12 +0000 (09:25 +0200)
If a workspace placeholder record is generated the field, that
is configured as label for a table, is filled with a placeholder.
This is a hardcoded string.
If database field does not allow strings (integer, double...)
a TYPO3 warning is displayed. "... Propably value mismatch ...".
This message is very confusing because the user does not know
where it comes from.

The label should be evaluated against the TCA eval configuration
before it is written to the database.

Resolves: #31757
Releases: 6.3, 6.2, 6.1
Change-Id: I18261359550dcaddaa9bd9ca0dd77f8300e81da9
Reviewed-on: https://review.typo3.org/22935
Reviewed-by: Alexander Opitz
Tested-by: Alexander Opitz
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Oliver Hader
Reviewed-by: Sascha Egerer
Tested-by: Sascha Egerer
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php

index 74b86ae..d1c3472 100644 (file)
@@ -1192,7 +1192,7 @@ class DataHandler {
                                                                                $newVersion_placeholderFieldArray['t3ver_state'] = (string)new VersionState(VersionState::NEW_PLACEHOLDER);
                                                                                // Setting workspace - only so display of place holders can filter out those from other workspaces.
                                                                                $newVersion_placeholderFieldArray['t3ver_wsid'] = $this->BE_USER->workspace;
-                                                                               $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['label']] = '[PLACEHOLDER, WS#' . $this->BE_USER->workspace . ']';
+                                                                               $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['label']] = $this->getPlaceholderTitleForTableLabel($table);
                                                                                // Saving placeholder as 'original'
                                                                                $this->insertDB($table, $id, $newVersion_placeholderFieldArray, FALSE);
                                                                                // For the actual new offline version, set versioning values to point to placeholder:
@@ -1278,6 +1278,23 @@ class DataHandler {
        }
 
        /**
+        * Create a placeholder title for the label field that does match the field requirements
+        *
+        * @param string $table The table name
+        * @return string placeholder value
+        */
+       protected function getPlaceholderTitleForTableLabel($table) {
+               $labelPlaceholder = '[PLACEHOLDER, WS#' . $this->BE_USER->workspace . ']';
+               $labelField = $GLOBALS['TCA'][$table]['ctrl']['label'];
+               if (!isset($GLOBALS['TCA'][$table]['columns'][$labelField]['config']['eval'])) {
+                       return $labelPlaceholder;
+               }
+               $evalCodesArray = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$labelField]['config']['eval'], TRUE);
+               $transformedLabel = $this->checkValue_input_Eval($labelPlaceholder, $evalCodesArray, '');
+               return isset($transformedLabel['value']) ? $transformedLabel['value'] : $labelPlaceholder;
+       }
+
+       /**
         * Filling in the field array
         * $this->exclude_array is used to filter fields if needed.
         *
index 22a827e..3337b96 100644 (file)
@@ -562,6 +562,61 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        }
 
        /**
+        * @param boolean $expected
+        * @param array $eval
+        * @dataProvider getPlaceholderTitleForTableLabelReturnsLabelThatsMatchesLabelFieldConditionsDataProvider
+        * @test
+        */
+       public function getPlaceholderTitleForTableLabelReturnsLabelThatsMatchesLabelFieldConditions($expected, $eval) {
+               $table = 'phpunit_dummy';
+
+               $subject = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Core\\DataHandling\\DataHandler',
+                       array('dummy')
+               );
+
+               $backendUser = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
+               $subject->BE_USER = $backendUser;
+               $subject->BE_USER->workspace = 1;
+
+               $GLOBALS['TCA'][$table] = array();
+               $GLOBALS['TCA'][$table]['ctrl'] = array('label' => 'dummy');
+               $GLOBALS['TCA'][$table]['columns'] = array(
+                       'dummy' => array(
+                               'config' => array(
+                                       'eval' => $eval
+                               )
+                       )
+               );
+
+               $this->assertEquals($expected, $subject->_call('getPlaceholderTitleForTableLabel', $table));
+       }
+
+       /**
+        * @return array
+        */
+       public function getPlaceholderTitleForTableLabelReturnsLabelThatsMatchesLabelFieldConditionsDataProvider() {
+               return array(
+                       array(
+                               0.10,
+                               'double2'
+                       ),
+                       array(
+                               0,
+                               'int'
+                       ),
+                       array(
+                               '0',
+                               'datetime'
+                       ),
+                       array(
+                               '[PLACEHOLDER, WS#1]',
+                               ''
+                       )
+               );
+       }
+
+       /**
         * @test
         */
        public function deleteRecord_procBasedOnFieldTypeRespectsEnableCascadingDelete() {