‪TYPO3CMS  9.5
SiteDatabaseEditRow.php
Go to the documentation of this file.
1 <?php
2 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 
23 
30 {
34  protected ‪$siteConfiguration;
35 
40  {
41  $this->siteConfiguration = ‪$siteConfiguration ?? GeneralUtility::makeInstance(
42  SiteConfiguration::class,
44  );
45  }
46 
54  public function ‪addData(array $result): array
55  {
56  if ($result['command'] !== 'edit' || !empty($result['databaseRow'])) {
57  return $result;
58  }
59 
60  $tableName = $result['tableName'];
61  $siteFinder = GeneralUtility::makeInstance(SiteFinder::class, $this->siteConfiguration);
62  if ($tableName === 'site') {
63  $rootPageId = (int)$result['vanillaUid'];
64  $rowData = $this->‪getRawConfigurationForSiteWithRootPageId($siteFinder, $rootPageId);
65  $result['databaseRow']['uid'] = $rowData['rootPageId'];
66  $result['databaseRow']['identifier'] = $result['customData']['siteIdentifier'];
67  } elseif (in_array($tableName, ['site_errorhandling', 'site_language', 'site_route', 'site_base_variant'], true)) {
68  $rootPageId = (int)($result['inlineTopMostParentUid'] ?? $result['inlineParentUid']);
69  $rowData = $this->‪getRawConfigurationForSiteWithRootPageId($siteFinder, $rootPageId);
70  $parentFieldName = $result['inlineParentFieldName'];
71  if (!isset($rowData[$parentFieldName])) {
72  throw new \RuntimeException('Field "' . $parentFieldName . '" not found', 1520886092);
73  }
74  $rowData = $rowData[$parentFieldName][$result['vanillaUid']];
75  $result['databaseRow']['uid'] = $result['vanillaUid'];
76  } else {
77  throw new \RuntimeException('Other tables not implemented', 1520886234);
78  }
79 
80  foreach ($rowData as $fieldName => $value) {
81  // Flat values only - databaseRow has no "tree"
82  if (!is_array($value)) {
83  $result['databaseRow'][$fieldName] = $value;
84  }
85  }
86  // All "records" are always on pid 0
87  $result['databaseRow']['pid'] = 0;
88  return $result;
89  }
90 
96  protected function ‪getRawConfigurationForSiteWithRootPageId(‪SiteFinder $siteFinder, int $rootPageId): array
97  {
98  $site = $siteFinder->‪getSiteByRootPageId($rootPageId);
99  // load config as it is stored on disk (without replacements)
100  $configuration = $this->siteConfiguration->load($site->getIdentifier());
101  if (isset($configuration['site'])) {
102  trigger_error(
103  'Site configuration with key \'site\' has been deprecated, remove indentation level and site key.',
104  E_USER_DEPRECATED
105  );
106  $configuration = $configuration['site'];
107  }
108  return $configuration;
109  }
110 }
‪TYPO3\CMS\Core\Site\SiteFinder\getSiteByRootPageId
‪Site getSiteByRootPageId(int $rootPageId)
Definition: SiteFinder.php:82
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Core\Configuration\SiteConfiguration
Definition: SiteConfiguration.php:38
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteDatabaseEditRow\__construct
‪__construct(SiteConfiguration $siteConfiguration=null)
Definition: SiteDatabaseEditRow.php:38
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteDatabaseEditRow\$siteConfiguration
‪SiteConfiguration $siteConfiguration
Definition: SiteDatabaseEditRow.php:33
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:2
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:22
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteDatabaseEditRow\getRawConfigurationForSiteWithRootPageId
‪array getRawConfigurationForSiteWithRootPageId(SiteFinder $siteFinder, int $rootPageId)
Definition: SiteDatabaseEditRow.php:95
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteDatabaseEditRow\addData
‪array addData(array $result)
Definition: SiteDatabaseEditRow.php:53
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Core\Core\Environment\getConfigPath
‪static string getConfigPath()
Definition: Environment.php:183
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteDatabaseEditRow
Definition: SiteDatabaseEditRow.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45