‪TYPO3CMS  10.4
CreateSiteConfiguration.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 
18 namespace ‪TYPO3\CMS\Core\Hooks;
19 
28 
35 {
39  protected ‪$allowedPageTypes = [
43  ];
44 
45  public function ‪processDatamap_afterDatabaseOperations(string $status, string $table, $id, array $fieldValues, ‪DataHandler $dataHandler): void
46  {
59  if ($status !== 'new'
60  || $table !== 'pages'
61  || $dataHandler->BE_USER->workspace > 0
62  || !isset($dataHandler->substNEWwithIDs[$id])
63  || (int)$fieldValues['pid'] !== 0
64  || (int)$fieldValues['l10n_parent'] !== 0
65  || (isset($fieldValues['t3ver_oid']) && (int)$fieldValues['t3ver_oid'] > 0)
66  || !in_array((int)$fieldValues['doktype'], $this->allowedPageTypes, true)
67  || $dataHandler->isImporting
68  ) {
69  return;
70  }
71 
72  $uid = (int)$dataHandler->substNEWwithIDs[$id];
73  $this->generateSiteConfigurationForRootPage($uid);
74  }
75 
76  protected function ‪generateSiteConfigurationForRootPage(int $pageId): void
77  {
78  $entryPoint = 'autogenerated-' . $pageId;
79  $siteIdentifier = $entryPoint . '-' . GeneralUtility::shortMD5((string)$pageId);
80 
81  if (!$this->‪siteExistsByRootPageId($pageId)) {
82  $siteConfiguration = GeneralUtility::makeInstance(SiteConfiguration::class);
83  $normalizedParams = $this->‪getNormalizedParams();
84  $basePrefix = ‪Environment::isCli() ? $normalizedParams->getSitePath() : $normalizedParams->getSiteUrl();
85  $siteConfiguration->createNewBasicSite(
86  $siteIdentifier,
87  $pageId,
88  $basePrefix . $entryPoint
89  );
90  $this->‪updateSlugForPage($pageId);
91  }
92  }
93 
94  protected function ‪getNormalizedParams(): ‪NormalizedParams
95  {
96  $normalizedParams = null;
97  $serverParams = ‪Environment::isCli() ? ['HTTP_HOST' => 'localhost'] : $_SERVER;
98  if (isset(‪$GLOBALS['TYPO3_REQUEST'])) {
99  $normalizedParams = ‪$GLOBALS['TYPO3_REQUEST']->getAttribute('normalizedParams');
100  $serverParams = ‪$GLOBALS['TYPO3_REQUEST']->getServerParams();
101  }
102 
103  if (!$normalizedParams instanceof ‪NormalizedParams) {
104  $normalizedParams = ‪NormalizedParams::createFromServerParams($serverParams);
105  }
106 
107  return $normalizedParams;
108  }
109 
115  protected function ‪updateSlugForPage(int $pageId): void
116  {
117  $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
118  $dataMap = [
119  'pages' => [
120  $pageId => [
121  'slug' => '',
122  ],
123  ],
124  ];
125  $dataHandler->start($dataMap, []);
126  $dataHandler->process_datamap();
127  }
128 
135  protected function ‪siteExistsByRootPageId(int $rootPageId): bool
136  {
137  try {
138  GeneralUtility::makeInstance(SiteFinder::class)->getSiteByRootPageId($rootPageId);
139  } catch (SiteNotFoundException $e) {
140  return false;
141  }
142  return true;
143  }
144 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:84
‪TYPO3\CMS\Core\Hooks\CreateSiteConfiguration\updateSlugForPage
‪updateSlugForPage(int $pageId)
Definition: CreateSiteConfiguration.php:114
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_DEFAULT
‪const DOKTYPE_DEFAULT
Definition: PageRepository.php:103
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_SHORTCUT
‪const DOKTYPE_SHORTCUT
Definition: PageRepository.php:105
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_LINK
‪const DOKTYPE_LINK
Definition: PageRepository.php:104
‪TYPO3\CMS\Core\Exception\SiteNotFoundException
Definition: SiteNotFoundException.php:26
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Core\Hooks\CreateSiteConfiguration\$allowedPageTypes
‪int[] $allowedPageTypes
Definition: CreateSiteConfiguration.php:38
‪TYPO3\CMS\Core\Hooks\CreateSiteConfiguration\siteExistsByRootPageId
‪bool siteExistsByRootPageId(int $rootPageId)
Definition: CreateSiteConfiguration.php:134
‪TYPO3\CMS\Core\Hooks\CreateSiteConfiguration
Definition: CreateSiteConfiguration.php:35
‪TYPO3\CMS\Core\Configuration\SiteConfiguration
Definition: SiteConfiguration.php:41
‪TYPO3\CMS\Core\Hooks\CreateSiteConfiguration\processDatamap_afterDatabaseOperations
‪processDatamap_afterDatabaseOperations(string $status, string $table, $id, array $fieldValues, DataHandler $dataHandler)
Definition: CreateSiteConfiguration.php:44
‪TYPO3\CMS\Core\Http\NormalizedParams\createFromServerParams
‪static static createFromServerParams(array $serverParams, array $systemConfiguration=null)
Definition: NormalizedParams.php:831
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Core\Hooks\CreateSiteConfiguration\generateSiteConfigurationForRootPage
‪generateSiteConfigurationForRootPage(int $pageId)
Definition: CreateSiteConfiguration.php:75
‪TYPO3\CMS\Core\Domain\Repository\PageRepository
Definition: PageRepository.php:52
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Core\Environment\isCli
‪static bool isCli()
Definition: Environment.php:154
‪TYPO3\CMS\Core\Hooks\CreateSiteConfiguration\getNormalizedParams
‪getNormalizedParams()
Definition: CreateSiteConfiguration.php:93
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:35
‪TYPO3\CMS\Core\Hooks
Definition: BackendUserGroupIntegrityCheck.php:16