TYPO3  7.6
DatabaseRowDefaultValues.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Form\FormDataProvider;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
27 {
34  public function addData(array $result)
35  {
36  $databaseRow = $result['databaseRow'];
37 
38  $newRow = $databaseRow;
39  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
40  // Keep current value if it can be resolved to "the is something" directly
41  if (isset($databaseRow[$fieldName])) {
42  $newRow[$fieldName] = $databaseRow[$fieldName];
43  continue;
44  }
45 
46  // Special handling for eval null
47  if (!empty($fieldConfig['config']['eval']) && GeneralUtility::inList($fieldConfig['config']['eval'], 'null')) {
48  if (// Field exists and is set to NULL
49  array_key_exists($fieldName, $databaseRow)
50  // Default NULL is set, and this is a new record!
51  || (array_key_exists('default', $fieldConfig['config']) && $fieldConfig['config']['default'] === null)
52  ) {
53  $newRow[$fieldName] = null;
54  } else {
55  $newRow[$fieldName] = (string)$fieldConfig['config']['default'];
56  }
57  } else {
58  // Fun part: This forces empty string for any field even if no default is set. Unsure if that is a good idea.
59  $newRow[$fieldName] = (string)$fieldConfig['config']['default'];
60  }
61  }
62 
63  $result['databaseRow'] = $newRow;
64 
65  return $result;
66  }
67 }