‪TYPO3CMS  ‪main
DatabaseRowDefaultAsReadonly.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 
28 {
34  public function ‪addData(array $result): array
35  {
36  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
37  if (!isset($result['defaultLanguageRow'][$fieldName])) {
38  // No default value available for this field
39  continue;
40  }
41  if (!‪GeneralUtility::inList(($result['processedTca']['columns'][$fieldName]['l10n_display'] ?? ''), 'defaultAsReadonly')) {
42  // defaultAsReadonly is not set for this field
43  continue;
44  }
45  if (!($result['databaseRow'][$result['processedTca']['ctrl']['languageField'] ?? null] ?? false)
46  || !($result['databaseRow'][$result['processedTca']['ctrl']['transOrigPointerField'] ?? null] ?? false)
47  ) {
48  // The current record is not an overlay. Note: This check might have already took place
49  // while creating the default language row. However, since this field might be set by
50  // other data providers unintentional, we check this here again to be sure.
51  continue;
52  }
53  if ((int)$result['databaseRow'][$result['processedTca']['ctrl']['transOrigPointerField']] !== (int)$result['defaultLanguageRow']['uid']) {
54  // The current records "transOrigPointerField" doesn't point to the current default language row
55  continue;
56  }
57 
58  // Override the current database field with the one from the default language
59  $result['databaseRow'][$fieldName] = $result['defaultLanguageRow'][$fieldName];
60  }
61 
62  return $result;
63  }
64 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDefaultAsReadonly
Definition: DatabaseRowDefaultAsReadonly.php:28
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDefaultAsReadonly\addData
‪addData(array $result)
Definition: DatabaseRowDefaultAsReadonly.php:34
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪TYPO3\CMS\Core\Utility\GeneralUtility\inList
‪static bool inList($list, $item)
Definition: GeneralUtility.php:422
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52