‪TYPO3CMS  ‪main
PageDoktypeRegistry.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 
23 
35 {
36  protected array ‪$pageTypes = [
38  'allowedTables' => '*',
39  ],
40  // Doktype 254 is a 'Folder' - a general purpose storage folder for whatever you like.
41  // In CMS context it's NOT a viewable page. Can contain any element.
43  'allowedTables' => '*',
44  ],
46  ],
47  // Even though both options look contradictory, the "allowedTables" key is used for other $pageTypes
48  // that have no custom definitions. So "allowedTables" works as a fallback for additional page types.
49  'default' => [
50  'allowedTables' => 'pages,sys_category,sys_file_reference,sys_file_collection',
51  'onlyAllowedTables' => false,
52  ],
53  ];
54 
59  public function ‪add(int $dokType, array $configuration): void
60  {
61  $this->pageTypes[$dokType] = array_replace(['onlyAllowedTables' => false], $configuration);
62  }
63 
64  public function ‪addAllowedRecordTypes(array $recordTypes, ?int $doktype = null): void
65  {
66  if ($recordTypes === []) {
67  return;
68  }
69  $doktype ??= 'default';
70  if (!isset($this->pageTypes[$doktype]['allowedTables'])) {
71  $this->pageTypes[$doktype]['allowedTables'] = '';
72  }
73  $this->pageTypes[$doktype]['allowedTables'] .= ',' . implode(',', $recordTypes);
74  }
75 
79  public function ‪isRecordTypeAllowedForDoktype(string $type, ?int $doktype): bool
80  {
81  $doktype ??= 'default';
82  $allowedTableList = $this->pageTypes[$doktype]['allowedTables'] ?? $this->pageTypes['default']['allowedTables'];
83  return str_contains($allowedTableList, '*') || ‪GeneralUtility::inList($allowedTableList, $type);
84  }
85 
89  public function ‪getRegisteredDoktypes(): array
90  {
91  $items = ‪$this->pageTypes;
92  unset($items['default']);
93  return array_keys($items);
94  }
95 
100  public function ‪doesDoktypeOnlyAllowSpecifiedRecordTypes(int $doktype = null): bool
101  {
102  $doktype = $doktype ?? 'default';
103  return $this->pageTypes[$doktype]['onlyAllowedTables'] ?? false;
104  }
105 
109  public function ‪getAllowedTypesForDoktype(int $doktype): array
110  {
111  $allowedTableList = $this->pageTypes[$doktype]['allowedTables'] ?? $this->pageTypes['default']['allowedTables'];
112  return explode(',', $allowedTableList);
113  }
114 
118  public function ‪exportConfiguration(): array
119  {
120  return ‪$this->pageTypes;
121  }
122 }
‪TYPO3\CMS\Core\DataHandling\PageDoktypeRegistry
Definition: PageDoktypeRegistry.php:35
‪TYPO3\CMS\Core\DataHandling\PageDoktypeRegistry\add
‪add(int $dokType, array $configuration)
Definition: PageDoktypeRegistry.php:59
‪TYPO3\CMS\Core\DataHandling
Definition: DataHandler.php:16
‪TYPO3\CMS\Core\DataHandling\PageDoktypeRegistry\addAllowedRecordTypes
‪addAllowedRecordTypes(array $recordTypes, ?int $doktype=null)
Definition: PageDoktypeRegistry.php:64
‪TYPO3\CMS\Core\DataHandling\PageDoktypeRegistry\getRegisteredDoktypes
‪getRegisteredDoktypes()
Definition: PageDoktypeRegistry.php:89
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_MOUNTPOINT
‪const DOKTYPE_MOUNTPOINT
Definition: PageRepository.php:102
‪TYPO3\CMS\Core\DataHandling\PageDoktypeRegistry\$pageTypes
‪array $pageTypes
Definition: PageDoktypeRegistry.php:36
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_BE_USER_SECTION
‪const DOKTYPE_BE_USER_SECTION
Definition: PageRepository.php:101
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_SYSFOLDER
‪const DOKTYPE_SYSFOLDER
Definition: PageRepository.php:104
‪TYPO3\CMS\Core\DataHandling\PageDoktypeRegistry\isRecordTypeAllowedForDoktype
‪isRecordTypeAllowedForDoktype(string $type, ?int $doktype)
Definition: PageDoktypeRegistry.php:79
‪TYPO3\CMS\Core\DataHandling\PageDoktypeRegistry\doesDoktypeOnlyAllowSpecifiedRecordTypes
‪doesDoktypeOnlyAllowSpecifiedRecordTypes(int $doktype=null)
Definition: PageDoktypeRegistry.php:100
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility\inList
‪static bool inList($list, $item)
Definition: GeneralUtility.php:422
‪TYPO3\CMS\Core\Domain\Repository\PageRepository
Definition: PageRepository.php:69
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\DataHandling\PageDoktypeRegistry\getAllowedTypesForDoktype
‪getAllowedTypesForDoktype(int $doktype)
Definition: PageDoktypeRegistry.php:109
‪TYPO3\CMS\Core\DataHandling\PageDoktypeRegistry\exportConfiguration
‪exportConfiguration()
Definition: PageDoktypeRegistry.php:118