[FEATURE] New option to disable the age display of dates per field by TCA 49/42849/6
authorChristian Seifert <christian-f-seifert@gmx.de>
Sun, 23 Aug 2015 18:13:46 +0000 (20:13 +0200)
committerPhilipp Gampe <philipp.gampe@typo3.org>
Mon, 31 Aug 2015 19:20:11 +0000 (21:20 +0200)
If an input field of a table is declared as "input" and evalued with
"date", record lists show the date with an automatically
calculated age. This is not needed, when a user only wants to see the date
and no further information about the age related to now.

This change enables integrators to disable the hard coded calculation by
a new TCA option called "disableAgeDisplay". Par example, to remove age
calculation for tt_content and the field "date", integrators can add the
following lines to the TCA:
$GLOBALS['TCA']['tt_content']['columns']['date']['config']
['disableAgeDisplay'] = true;

So, disabling the age display can be configured per table and field.

Resolves: #28243
Releases: master
Change-Id: Id2ce6512764881889b4181f73db36048d5704be8
Reviewed-on: http://review.typo3.org/42849
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Mats Svensson <mats@pixelant.se>
Tested-by: Mats Svensson <mats@pixelant.se>
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php
typo3/sysext/core/Documentation/Changelog/master/Feature-28243-IntroduceTcaOptionToDisableAgeDisplay.rst [new file with mode: 0644]

index fce9b8b..6d2830e 100755 (executable)
@@ -2404,7 +2404,18 @@ class BackendUtility {
                                                        $value = $value !== $emptyValue ? strtotime($value) : 0;
                                                }
                                                if (!empty($value)) {
-                                                       $l = self::date($value) . ' (' . ($GLOBALS['EXEC_TIME'] - $value > 0 ? '-' : '') . self::calcAge(abs(($GLOBALS['EXEC_TIME'] - $value)), $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')) . ')';
+                                                       $ageSuffix = '';
+                                                       $dateColumnConfiguration = $GLOBALS['TCA'][$table]['columns'][$col]['config'];
+                                                       $ageDisplayKey = 'disableAgeDisplay';
+
+                                                       // generate age suffix as long as not explicitly suppressed
+                                                       if (!isset($dateColumnConfiguration[$ageDisplayKey])
+                                                                       // non typesafe comparison on intention
+                                                               || $dateColumnConfiguration[$ageDisplayKey] == FALSE) {
+                                                               $ageSuffix = ' (' . ($GLOBALS['EXEC_TIME'] - $value > 0 ? '-' : '') . self::calcAge(abs(($GLOBALS['EXEC_TIME'] - $value)), $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')) . ')';
+                                                       }
+
+                                                       $l = self::date($value) . $ageSuffix;
                                                }
                                        } elseif (GeneralUtility::inList($theColConf['eval'], 'time')) {
                                                if (!empty($value)) {
index cc0c632..70724fd 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Backend\Tests\Unit\Utility;
  * The TYPO3 project - inspiring people to share!
  */
 
+use Prophecy\Argument;
+use Prophecy\Prophecy\ObjectProphecy;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ProcessedValueForGroupWithOneAllowedTableFixture;
 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ProcessedValueForGroupWithMultipleAllowedTablesFixture;
@@ -117,6 +119,7 @@ class BackendUtilityTest extends UnitTestCase {
        /**
         * @test
         * @dataProvider calcAgeDataProvider
+        *
         * @param int $seconds
         * @param string $expectedLabel
         */
@@ -218,28 +221,29 @@ class BackendUtilityTest extends UnitTestCase {
                $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection::class, array(), array(), '', FALSE);
                $GLOBALS['TYPO3_DB']->expects($this->any())->method('fullQuoteStr')
                        ->will($this->returnCallback(
-                               function($quoteStr) {
+                               function ($quoteStr) {
                                        return "'" . $quoteStr . "'";
                                }
-                       ));
+                       )
+                       );
                $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTquery')->will($this->returnValue(0));
                $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_free_result');
                $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_fetch_assoc')
                        ->will($this->returnCallback(
-                               function() {
+                               function () {
                                        static $called = 0;
                                        ++$called;
                                        switch ($called) {
                                                // SELECT * FROM sys_category_record_mm
                                                case 1:
                                                        return array(
-                                                               'uid_local' => 1,       // uid of a sys_category record
-                                                               'uid_foreign' => 1,     // uid of a pages record
+                                                               'uid_local' => 1,    // uid of a sys_category record
+                                                               'uid_foreign' => 1,    // uid of a pages record
                                                        );
                                                case 2:
                                                        return array(
-                                                               'uid_local' => 2,       // uid of a sys_category record
-                                                               'uid_foreign' => 1,     // uid of a pages record
+                                                               'uid_local' => 2,    // uid of a sys_category record
+                                                               'uid_foreign' => 1,    // uid of a pages record
                                                        );
                                                case 3:
                                                        return NULL;
@@ -259,7 +263,8 @@ class BackendUtilityTest extends UnitTestCase {
                                        }
                                        return NULL;
                                }
-                       ));
+                       )
+                       );
 
                $GLOBALS['TCA'] = array(
                        'pages' => array(
@@ -297,6 +302,88 @@ class BackendUtilityTest extends UnitTestCase {
        }
 
        /**
+        * @test
+        */
+       public function getProcessedValueDisplaysAgeForDateInputFieldsIfSettingAbsent() {
+               /** @var ObjectProphecy $languageServiceProphecy */
+               $languageServiceProphecy = $this->prophesize(LanguageService::class);
+               $languageServiceProphecy->sL(Argument::cetera())->willReturn(' min| hrs| days| yrs| min| hour| day| year');
+               $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
+
+               $GLOBALS['EXEC_TIME'] = mktime(0, 0, 0, 8, 30, 2015);
+
+               $GLOBALS['TCA'] = [
+                       'tt_content' => [
+                               'columns' => [
+                                       'date' => [
+                                               'config' => [
+                                                       'type' => 'input',
+                                                       'eval' => 'date',
+                                               ],
+                                       ],
+                               ],
+                       ],
+               ];
+               $this->assertSame('28-08-15 (-2 days)', BackendUtility::getProcessedValue('tt_content', 'date', mktime(0, 0, 0, 8, 28, 2015)));
+       }
+
+       /**
+        * @return array
+        */
+       public function inputTypeDateDisplayOptions() {
+               return [
+                       'typeSafe Setting' => [
+                               TRUE,
+                               '28-08-15',
+                       ],
+                       'non typesafe setting' => [
+                               1,
+                               '28-08-15',
+                       ],
+                       'setting disabled typesafe' => [
+                               FALSE,
+                               '28-08-15 (-2 days)',
+                       ],
+                       'setting disabled not typesafe' => [
+                               0,
+                               '28-08-15 (-2 days)',
+                       ],
+               ];
+       }
+
+       /**
+        * @test
+        *
+        * @dataProvider inputTypeDateDisplayOptions
+        *
+        * @param string $input
+        * @param string $expected
+        */
+       public function getProcessedValueHandlesAgeDisplayCorrectly($input, $expected) {
+               /** @var ObjectProphecy $languageServiceProphecy */
+               $languageServiceProphecy = $this->prophesize(LanguageService::class);
+               $languageServiceProphecy->sL(Argument::cetera())->willReturn(' min| hrs| days| yrs| min| hour| day| year');
+               $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
+
+               $GLOBALS['EXEC_TIME'] = mktime(0, 0, 0, 8, 30, 2015);
+
+               $GLOBALS['TCA'] = [
+                       'tt_content' => [
+                               'columns' => [
+                                       'date' => [
+                                               'config' => [
+                                                       'type' => 'input',
+                                                       'eval' => 'date',
+                                                       'disableAgeDisplay' => $input,
+                                               ],
+                                       ],
+                               ],
+                       ],
+               ];
+               $this->assertSame($expected, BackendUtility::getProcessedValue('tt_content', 'date', mktime(0, 0, 0, 8, 28, 2015)));
+       }
+
+       /**
         * Tests concerning getCommonSelectFields
         */
 
@@ -402,6 +489,7 @@ class BackendUtilityTest extends UnitTestCase {
        /**
         * @test
         * @dataProvider getCommonSelectFieldsReturnsCorrectFieldsDataProvider
+        *
         * @param string $table
         * @param string $prefix
         * @param array $presetFields
@@ -489,6 +577,7 @@ class BackendUtilityTest extends UnitTestCase {
        /**
         * @test
         * @dataProvider getLabelFromItemlistReturnsCorrectFieldsDataProvider
+        *
         * @param string $table
         * @param string $col
         * @param string $key
@@ -558,6 +647,7 @@ class BackendUtilityTest extends UnitTestCase {
        /**
         * @test
         * @dataProvider getLabelFromItemListMergedReturnsCorrectFieldsDataProvider
+        *
         * @param int $pageId
         * @param string $table
         * @param string $column
@@ -638,6 +728,7 @@ class BackendUtilityTest extends UnitTestCase {
        /**
         * @test
         * @dataProvider getLabelsFromItemsListDataProvider
+        *
         * @param string $table
         * @param string $col
         * @param string $keyList
@@ -651,7 +742,7 @@ class BackendUtilityTest extends UnitTestCase {
                $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
 
                $GLOBALS['TCA'][$table] = $tca;
-               $label = BackendUtility::getLabelsFromItemsList($table, $col, $keyList,$pageTsConfig);
+               $label = BackendUtility::getLabelsFromItemsList($table, $col, $keyList, $pageTsConfig);
                $this->assertEquals($expectedLabel, $label);
        }
 
@@ -1105,9 +1196,11 @@ class BackendUtilityTest extends UnitTestCase {
        /**
         * @test
         * @dataProvider replaceMarkersInWhereClauseDataProvider
+        *
         * @param string $whereClause
         * @param array $tsConfig
         * @param string $expected
+        *
         * @throws \PHPUnit_Framework_Exception
         */
        public function replaceMarkersInWhereClauseReturnsValidWhereClause($whereClause, array $tsConfig, $expected) {
@@ -1116,10 +1209,11 @@ class BackendUtilityTest extends UnitTestCase {
                $GLOBALS['TYPO3_DB']->expects($this->any())->method('quoteStr')->will($this->returnArgument(0));
                $GLOBALS['TYPO3_DB']->expects($this->any())->method('fullQuoteStr')
                        ->will($this->returnCallback(
-                               function($quoteStr) {
+                               function ($quoteStr) {
                                        return "'" . $quoteStr . "'";
                                }
-                       ));
+                       )
+                       );
                $GLOBALS['TYPO3_DB']->expects($this->any())->method('cleanIntList')->will($this->returnArgument(0));
                $this->assertSame($expected, BackendUtility::replaceMarkersInWhereClause($whereClause, 'dummytable', 'dummyfield', $tsConfig));
        }
@@ -1177,6 +1271,7 @@ class BackendUtilityTest extends UnitTestCase {
 
        /**
         * Data provider for replaceL10nModeFieldsReplacesFields
+        *
         * @return array
         */
        public function replaceL10nModeFieldsReplacesFieldsDataProvider() {
@@ -1311,11 +1406,13 @@ class BackendUtilityTest extends UnitTestCase {
        /**
         * @test
         * @dataProvider replaceL10nModeFieldsReplacesFieldsDataProvider
+        *
         * @param string $table
         * @param array $row
         * @param array $tca
         * @param array $originalRow
         * @param array $expected
+        *
         * @throws \InvalidArgumentException
         * @throws \PHPUnit_Framework_Exception
         */
@@ -1354,5 +1451,4 @@ class BackendUtilityTest extends UnitTestCase {
                );
                $this->assertEquals($expected, BackendUtility::getSpecConfParts($defaultExtras));
        }
-
 }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-28243-IntroduceTcaOptionToDisableAgeDisplay.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-28243-IntroduceTcaOptionToDisableAgeDisplay.rst
new file mode 100644 (file)
index 0000000..b300b42
--- /dev/null
@@ -0,0 +1,19 @@
+================================================================================
+Feature: #28243 - Introduce TCA option to disable age display of dates per field
+================================================================================
+
+Description
+===========
+
+It is now possible to disable the display of the age (p.e. "2015-08-30 (-27 days)") of date fields in record
+listings by a new TCA option.
+The option is called "disableAgeDisplay" and can be set in the config section of a field.
+It will be respected if the field has the type "input" and its eval is set to "date".
+
+Example
+-------
+
+.. code-block:: php
+
+       // disables the display of " (-27 days)" p.e.
+       $GLOBALS['TCA']['tt_content']['columns']['date']['config']['disableAgeDisplay'] = true;
\ No newline at end of file