‪TYPO3CMS  10.4
SiteDatabaseEditRow.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 
24 
31 {
35  protected ‪$siteConfiguration;
36 
38  {
39  $this->siteConfiguration = ‪$siteConfiguration;
40  }
41 
49  public function ‪addData(array $result): array
50  {
51  if ($result['command'] !== 'edit' || !empty($result['databaseRow'])) {
52  return $result;
53  }
54 
55  $tableName = $result['tableName'];
56  $siteFinder = GeneralUtility::makeInstance(SiteFinder::class, $this->siteConfiguration);
57  if ($tableName === 'site') {
58  $rootPageId = (int)$result['vanillaUid'];
59  $rowData = $this->‪getRawConfigurationForSiteWithRootPageId($siteFinder, $rootPageId);
60  $result['databaseRow']['uid'] = $rowData['rootPageId'];
61  $result['databaseRow']['identifier'] = $result['customData']['siteIdentifier'];
62  } elseif (in_array($tableName, ['site_errorhandling', 'site_language', 'site_route', 'site_base_variant'], true)) {
63  $rootPageId = (int)($result['inlineTopMostParentUid'] ?? $result['inlineParentUid']);
64  $rowData = $this->‪getRawConfigurationForSiteWithRootPageId($siteFinder, $rootPageId);
65  $parentFieldName = $result['inlineParentFieldName'];
66  if (!isset($rowData[$parentFieldName])) {
67  throw new \RuntimeException('Field "' . $parentFieldName . '" not found', 1520886092);
68  }
69  $rowData = $rowData[$parentFieldName][$result['vanillaUid']];
70  $result['databaseRow']['uid'] = $result['vanillaUid'];
71  } else {
72  throw new \RuntimeException('Other tables not implemented', 1520886234);
73  }
74 
75  foreach ($rowData as $fieldName => $value) {
76  // Flat values only - databaseRow has no "tree"
77  if (!is_array($value)) {
78  $result['databaseRow'][$fieldName] = $value;
79  }
80  }
81  // All "records" are always on pid 0
82  $result['databaseRow']['pid'] = 0;
83  return $result;
84  }
85 
91  protected function ‪getRawConfigurationForSiteWithRootPageId(SiteFinder $siteFinder, int $rootPageId): array
92  {
93  $site = $siteFinder->getSiteByRootPageId($rootPageId);
94  // load config as it is stored on disk (without replacements)
95  return $this->siteConfiguration->load($site->getIdentifier());
96  }
97 }
‪TYPO3\CMS\Core\Site\SiteFinder\getSiteByRootPageId
‪Site getSiteByRootPageId(int $rootPageId)
Definition: SiteFinder.php:79
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Core\Configuration\SiteConfiguration
Definition: SiteConfiguration.php:41
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteDatabaseEditRow\$siteConfiguration
‪SiteConfiguration $siteConfiguration
Definition: SiteDatabaseEditRow.php:34
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteDatabaseEditRow\__construct
‪__construct(SiteConfiguration $siteConfiguration)
Definition: SiteDatabaseEditRow.php:36
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteDatabaseEditRow\getRawConfigurationForSiteWithRootPageId
‪array getRawConfigurationForSiteWithRootPageId(SiteFinder $siteFinder, int $rootPageId)
Definition: SiteDatabaseEditRow.php:90
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteDatabaseEditRow\addData
‪array addData(array $result)
Definition: SiteDatabaseEditRow.php:48
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteDatabaseEditRow
Definition: SiteDatabaseEditRow.php:31
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46