‪TYPO3CMS  ‪main
SiteResolving.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 
26 
35 {
39  protected ‪$siteFinder;
40 
41  public function ‪__construct(‪SiteFinder ‪$siteFinder = null)
42  {
43  $this->siteFinder = ‪$siteFinder ?? GeneralUtility::makeInstance(SiteFinder::class);
44  }
45 
49  public function ‪addData(array $result): array
50  {
51  if ($result['defaultLanguagePageRow']['t3ver_oid'] ?? null) {
52  $pageIdDefaultLanguage = (int)$result['defaultLanguagePageRow']['t3ver_oid'];
53  } elseif ($result['defaultLanguagePageRow']['uid'] ?? null) {
54  $pageIdDefaultLanguage = (int)$result['defaultLanguagePageRow']['uid'];
55  } elseif (array_key_exists('tableName', $result) && $result['tableName'] === 'pages') {
56  if (!empty($result['databaseRow']['t3ver_oid'])) {
57  $pageIdDefaultLanguage = $result['databaseRow']['t3ver_oid'];
58  } else {
59  $pageIdDefaultLanguage = $result['databaseRow']['uid'] ?? $result['effectivePid'];
60  }
61  } else {
62  $pageIdDefaultLanguage = $result['effectivePid'];
63  }
64  $result['site'] = $this->‪resolveSite((int)$pageIdDefaultLanguage);
65  return $result;
66  }
67 
68  protected function ‪resolveSite(int $pageId): ‪SiteInterface
69  {
70  try {
71  return $this->siteFinder->getSiteByPageId($pageId);
72  } catch (‪SiteNotFoundException $e) {
73  return new ‪NullSite();
74  }
75  }
76 }
‪TYPO3\CMS\Core\Site\Entity\SiteInterface
Definition: SiteInterface.php:26
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteResolving
Definition: SiteResolving.php:35
‪TYPO3\CMS\Core\Site\Entity\NullSite
Definition: NullSite.php:32
‪TYPO3\CMS\Core\Exception\SiteNotFoundException
Definition: SiteNotFoundException.php:25
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteResolving\__construct
‪__construct(SiteFinder $siteFinder=null)
Definition: SiteResolving.php:40
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteResolving\addData
‪addData(array $result)
Definition: SiteResolving.php:48
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteResolving\$siteFinder
‪SiteFinder $siteFinder
Definition: SiteResolving.php:38
‪TYPO3\CMS\Backend\Form\FormDataProvider\SiteResolving\resolveSite
‪resolveSite(int $pageId)
Definition: SiteResolving.php:67
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52