BE_USER->workspace > 0 || !isset($dataHandler->substNEWwithIDs[$id]) || (int)($fieldValues['l10n_parent'] ?? 0) !== 0 || ((int)$fieldValues['pid'] !== 0 && !($fieldValues['is_siteroot'] ?? false)) || (isset($fieldValues['t3ver_oid']) && (int)$fieldValues['t3ver_oid'] > 0) || !in_array((int)$fieldValues['doktype'], $this->allowedPageTypes, true) || $dataHandler->isImporting ) { return; } $uid = (int)$dataHandler->substNEWwithIDs[$id]; $this->generateSiteConfigurationForRootPage($uid, $dataHandler->BE_USER); } protected function generateSiteConfigurationForRootPage(int $pageId, BackendUserAuthentication $backendUser): void { $entryPoint = 'autogenerated-' . $pageId; $siteIdentifier = $entryPoint . '-' . md5((string)$pageId); if (!$this->siteExistsByRootPageId($pageId)) { $siteWriter = GeneralUtility::makeInstance(SiteWriter::class); $normalizedParams = $this->getNormalizedParams(); $basePrefix = Environment::isCli() ? $normalizedParams->getSitePath() : $normalizedParams->getSiteUrl(); try { $siteWriter->createNewBasicSite( $siteIdentifier, $pageId, $basePrefix . $entryPoint ); $backendUser->writelog(Type::SITE, SiteAction::CREATE, SystemLogErrorClassification::MESSAGE, null, 'Site configuration \'%s\' was automatically created for new root page (%s).', [$siteIdentifier, $pageId], 'site'); $this->updateSlugForPage($pageId); } catch (SiteConfigurationWriteException $e) { $flashMessage = new FlashMessage($e->getMessage(), '', ContextualFeedbackSeverity::WARNING, true); $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class); $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier(); $defaultFlashMessageQueue->enqueue($flashMessage); } } } protected function getNormalizedParams(): NormalizedParams { $normalizedParams = null; $serverParams = Environment::isCli() ? ['HTTP_HOST' => 'localhost'] : $_SERVER; if (isset($GLOBALS['TYPO3_REQUEST'])) { $normalizedParams = $GLOBALS['TYPO3_REQUEST']->getAttribute('normalizedParams'); $serverParams = $GLOBALS['TYPO3_REQUEST']->getServerParams(); } if (!$normalizedParams instanceof NormalizedParams) { $normalizedParams = NormalizedParams::createFromServerParams($serverParams); } return $normalizedParams; } /** * Updates the slug of the given pageId by spinning up a new DataHandler instance. */ protected function updateSlugForPage(int $pageId): void { $dataHandler = GeneralUtility::makeInstance(DataHandler::class); $dataMap = [ 'pages' => [ $pageId => [ 'slug' => '', ], ], ]; $dataHandler->start($dataMap, []); $dataHandler->process_datamap(); } /** * Checks whether a site exists by its root page. Sets up a new SiteFinder instance * * @param int $rootPageId the page ID (default language) */ protected function siteExistsByRootPageId(int $rootPageId): bool { try { GeneralUtility::makeInstance(SiteFinder::class)->getSiteByRootPageId($rootPageId); } catch (SiteNotFoundException $e) { return false; } return true; } }