‪TYPO3CMS  10.4
DatabaseRowDefaultValues.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 
28 {
35  public function ‪addData(array $result)
36  {
37  $databaseRow = $result['databaseRow'];
38 
39  $newRow = $databaseRow;
40  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
41  // Keep current value if it can be resolved to "there is something" directly
42  if (isset($databaseRow[$fieldName])) {
43  $newRow[$fieldName] = $databaseRow[$fieldName];
44  continue;
45  }
46 
47  // Special handling for eval null
48  if (!empty($fieldConfig['config']['eval']) && GeneralUtility::inList($fieldConfig['config']['eval'], 'null')) {
49  if (// Field exists and is set to NULL
50  array_key_exists($fieldName, $databaseRow)
51  // Default NULL is set, and this is a new record!
52  || (array_key_exists('default', $fieldConfig['config']) && $fieldConfig['config']['default'] === null)
53  ) {
54  $newRow[$fieldName] = null;
55  } else {
56  $newRow[$fieldName] = (string)$fieldConfig['config']['default'];
57  }
58  } else {
59  // Fun part: This forces empty string for any field even if no default is set. This is
60  // a useful side effect in flex form section containers where a new field is added to an existing
61  // value array because it was added to a data structure.
62  $newRow[$fieldName] = (string)$fieldConfig['config']['default'];
63  }
64  }
65 
66  $result['databaseRow'] = $newRow;
67 
68  return $result;
69  }
70 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDefaultValues
Definition: DatabaseRowDefaultValues.php:28
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDefaultValues\addData
‪array addData(array $result)
Definition: DatabaseRowDefaultValues.php:35
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46