60 lines
2.4 KiB
PHP
Executable File
60 lines
2.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Evoweb\EwBase\Xclass;
|
|
|
|
use TYPO3\CMS\Backend\Form\FormDataProvider\SiteDatabaseEditRow as BaseSiteDatabaseEditRow;
|
|
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
|
|
use TYPO3\CMS\Core\Site\SiteFinder;
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
|
class SiteDatabaseEditRow extends BaseSiteDatabaseEditRow
|
|
{
|
|
/**
|
|
* First level of ['customData']['siteData'] to ['databaseRow']
|
|
*
|
|
* @param array $result
|
|
* @return array
|
|
* @throws \RuntimeException
|
|
*/
|
|
public function addData(array $result): array
|
|
{
|
|
if ($result['command'] !== 'edit' || !empty($result['databaseRow'])) {
|
|
return $result;
|
|
}
|
|
|
|
$tableName = $result['tableName'];
|
|
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class, $this->siteConfiguration);
|
|
if ($tableName === 'site') {
|
|
$rootPageId = (int)$result['vanillaUid'];
|
|
$rowData = $this->getRawConfigurationForSiteWithRootPageId($siteFinder, $rootPageId);
|
|
$result['databaseRow']['uid'] = $rowData['rootPageId'];
|
|
$result['databaseRow']['identifier'] = $result['customData']['siteIdentifier'];
|
|
} elseif (in_array($tableName, ['site_errorhandling', 'site_language', 'site_route', 'site_base_variant'], true)) {
|
|
$rootPageId = (int)($result['inlineTopMostParentUid'] ?? $result['inlineParentUid']);
|
|
try {
|
|
$rowData = $this->getRawConfigurationForSiteWithRootPageId($siteFinder, $rootPageId);
|
|
$parentFieldName = $result['inlineParentFieldName'];
|
|
if (!isset($rowData[$parentFieldName])) {
|
|
throw new \RuntimeException('Field "' . $parentFieldName . '" not found', 1520886092);
|
|
}
|
|
$rowData = $rowData[$parentFieldName][$result['vanillaUid']];
|
|
$result['databaseRow']['uid'] = $result['vanillaUid'];
|
|
} catch (SiteNotFoundException $e) {
|
|
$rowData = [];
|
|
}
|
|
} else {
|
|
return $result;
|
|
}
|
|
|
|
foreach ($rowData as $fieldName => $value) {
|
|
// Flat values only - databaseRow has no "tree"
|
|
if (!is_array($value)) {
|
|
$result['databaseRow'][$fieldName] = $value;
|
|
}
|
|
}
|
|
// All "records" are always on pid 0
|
|
$result['databaseRow']['pid'] = 0;
|
|
return $result;
|
|
}
|
|
}
|