‪TYPO3CMS  9.5
PseudoSiteTcaDisplayCondition.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 
21 
35 {
44  public function ‪isInPseudoSite(array $parameters): bool
45  {
46  if (!isset($parameters['conditionParameters'][0])
47  || $parameters['conditionParameters'][0] !== 'pages'
48  || !isset($parameters['conditionParameters'][1])
49  || (!in_array($parameters['conditionParameters'][1], ['true', 'false'], true))
50  || empty($parameters['record']['uid'])
51  ) {
52  // Validate arguments
53  throw new \InvalidArgumentException(
54  'Invalid arguments using isInPseudoSite display condition',
55  1535055415
56  );
57  }
58 
59  // uid is set if we're editing an existing page
60  // This resolves to 0 if the page is 'new'
61  $defaultLanguagePageId = (int)($parameters['record']['t3ver_oid'] ?: $parameters['record']['uid']);
62  if (is_array($parameters['record']['l10n_parent'])
63  && (int)$parameters['record']['sys_language_uid'][0] > 0
64  ) {
65  // But if the page is a localized page, we take the l10n_parent as uid for the sitematcher
66  $defaultLanguagePageId = (int)$parameters['record']['l10n_parent'][0];
67  }
68  // If still 0, this is probably a 'new' page somewhere, so we take the pid
69  // For additional fun, pid can be -1*real-pid, if the new page is created "after" an existing page
70  // Also take care if a record is a localized one, so set the pid instead of the parent (language) record
71  if ($defaultLanguagePageId === 0
72  || (int)$parameters['record']['sys_language_uid'][0] > 0
73  ) {
74  $defaultLanguagePageId = abs((int)$parameters['record']['pid']);
75  }
76  // And if now still 0, this is a 'new' page below pid 0. This will resolve to a 'NullSite' object
77 
78  // If not a Site or a NullSite object, it must be a PseudoSite. We show the slug for
79  // NullSites (new pages below root) to simplify the editing workflow a bit.
80  $site = GeneralUtility::makeInstance(SiteMatcher::class)->matchByPageId($defaultLanguagePageId);
81  $isInPseudoSite = ($site instanceof ‪PseudoSite);
82 
83  if ($parameters['conditionParameters'][1] === 'false') {
84  // Negate if requested
85  return !$isInPseudoSite;
86  }
87 
88  return $isInPseudoSite;
89  }
90 }
‪TYPO3\CMS\Core\Compatibility\PseudoSiteTcaDisplayCondition\isInPseudoSite
‪bool isInPseudoSite(array $parameters)
Definition: PseudoSiteTcaDisplayCondition.php:44
‪TYPO3\CMS\Core\Compatibility\PseudoSiteTcaDisplayCondition
Definition: PseudoSiteTcaDisplayCondition.php:35
‪TYPO3\CMS\Core\Site\Entity\PseudoSite
Definition: PseudoSite.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Compatibility
Definition: LoadedExtensionArrayElement.php:2
‪TYPO3\CMS\Core\Routing\SiteMatcher
Definition: SiteMatcher.php:53