‪TYPO3CMS  ‪main
DatabaseRowDateTimeFields.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
25 {
31  public function ‪addData(array $result)
32  {
33  $dateTimeTypes = ‪QueryHelper::getDateTimeTypes();
34  $dateTimeFormats = ‪QueryHelper::getDateTimeFormats();
35 
36  foreach ($result['processedTca']['columns'] as $column => $columnConfig) {
37  if (($columnConfig['config']['type'] ?? '') !== 'datetime'
38  || !in_array($columnConfig['config']['dbType'] ?? '', $dateTimeTypes, true)
39  ) {
40  // it's a UNIX timestamp! We do not modify this here, as it will only be treated as a datetime because
41  // of eval being set to "date" or "datetime". This is handled in InputTextElement then.
42  continue;
43  }
44  // ensure the column's value is set
45  $result['databaseRow'][$column] = $result['databaseRow'][$column] ?? null;
46 
47  // Nullable fields do not need treatment
48  $isNullable = $columnConfig['config']['nullable'] ?? false;
49  if ($isNullable && $result['databaseRow'][$column] === null) {
50  continue;
51  }
52 
53  $format = $dateTimeFormats[$columnConfig['config']['dbType']] ?? [];
54  $emptyValueFormat = $format['empty'] ?? null;
55  if (!empty($result['databaseRow'][$column]) && $result['databaseRow'][$column] !== $emptyValueFormat) {
56  // Create an ISO-8601 date from current field data; the database always contains UTC
57  // The field value is something like "2016-01-01" or "2016-01-01 10:11:12", so appending "UTC"
58  // makes date() treat it as a UTC date (which is what we store in the database).
59  $result['databaseRow'][$column] = date('c', (int)strtotime($result['databaseRow'][$column] . ' UTC'));
60  } else {
61  $result['databaseRow'][$column] = $format['reset'] ?? null;
62  }
63  }
64  return $result;
65  }
66 }
‪TYPO3\CMS\Core\Database\Query\QueryHelper\getDateTimeFormats
‪static array getDateTimeFormats()
Definition: QueryHelper.php:183
‪TYPO3\CMS\Core\Database\Query\QueryHelper
Definition: QueryHelper.php:32
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDateTimeFields
Definition: DatabaseRowDateTimeFields.php:25
‪TYPO3\CMS\Core\Database\Query\QueryHelper\getDateTimeTypes
‪static array getDateTimeTypes()
Definition: QueryHelper.php:211
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDateTimeFields\addData
‪array addData(array $result)
Definition: DatabaseRowDateTimeFields.php:31
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23