‪TYPO3CMS  ‪main
Page.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\Domain;
19 
23 class ‪Page implements \ArrayAccess
24 {
25  use ‪PropertyTrait;
26 
27  protected array ‪$specialPropertyNames = [
28  '_language',
29  '_LOCALIZED_UID',
30  '_MP_PARAM',
31  '_ORIG_uid',
32  '_ORIG_pid',
33  '_SHORTCUT_ORIGINAL_PAGE_UID',
34  '_PAGES_OVERLAY',
35  '_PAGES_OVERLAY_UID',
36  '_PAGES_OVERLAY_LANGUAGE',
37  '_PAGES_OVERLAY_REQUESTEDLANGUAGE',
38  '_TRANSLATION_SOURCE',
39  ];
40 
41  protected array ‪$specialProperties = [];
42 
43  public function ‪__construct(array $properties)
44  {
45  foreach ($properties as $propertyName => $propertyValue) {
46  if (in_array($propertyName, $this->specialPropertyNames)) {
47  if ($propertyName === '_TRANSLATION_SOURCE' && !$propertyValue instanceof ‪Page) {
48  $this->specialProperties[$propertyName] = new ‪Page($propertyValue);
49  } else {
50  $this->specialProperties[$propertyName] = $propertyValue;
51  }
52  } else {
53  $this->properties[$propertyName] = $propertyValue;
54  }
55  }
56  }
57 
58  public function ‪getLanguageId(): int
59  {
60  return $this->specialProperties['_language'] ?? $this->specialProperties['_PAGES_OVERLAY_LANGUAGE'] ?? $this->properties['sys_language_uid'];
61  }
62 
63  public function ‪getPageId(): int
64  {
65  $pageId = isset($this->properties['l10n_parent']) && $this->properties['l10n_parent'] > 0 ? $this->properties['l10n_parent'] : $this->properties['uid'];
66  return (int)$pageId;
67  }
68 
69  public function ‪getTranslationSource(): ?‪Page
70  {
71  return $this->specialProperties['_TRANSLATION_SOURCE'] ?? null;
72  }
73 
74  public function ‪getRequestedLanguage(): ?int
75  {
76  return $this->specialProperties['_PAGES_OVERLAY_REQUESTEDLANGUAGE'] ?? null;
77  }
78 
79  public function ‪toArray(bool $includeSpecialProperties = false): array
80  {
81  if ($includeSpecialProperties) {
82  return $this->properties + ‪$this->specialProperties;
83  }
84  return $this->properties;
85  }
86 }
‪TYPO3\CMS\Core\Domain\Page\getPageId
‪getPageId()
Definition: Page.php:63
‪TYPO3\CMS\Core\Domain\Page
Definition: Page.php:24
‪TYPO3\CMS\Core\Domain\Page\$specialProperties
‪array $specialProperties
Definition: Page.php:41
‪TYPO3\CMS\Core\Domain\PropertyTrait
Definition: PropertyTrait.php:24
‪TYPO3\CMS\Core\Domain
‪TYPO3\CMS\Core\Domain\Page\toArray
‪toArray(bool $includeSpecialProperties=false)
Definition: Page.php:79
‪TYPO3\CMS\Core\Domain\Page\getTranslationSource
‪getTranslationSource()
Definition: Page.php:69
‪TYPO3\CMS\Core\Domain\Page\getLanguageId
‪getLanguageId()
Definition: Page.php:58
‪TYPO3\CMS\Core\Domain\Page\$specialPropertyNames
‪array $specialPropertyNames
Definition: Page.php:27
‪TYPO3\CMS\Core\Domain\Page\getRequestedLanguage
‪getRequestedLanguage()
Definition: Page.php:74
‪TYPO3\CMS\Core\Domain\Page\__construct
‪__construct(array $properties)
Definition: Page.php:43