Skip to content

Commit bbda712

Browse files
committed
[FEATURE] Allowed Record Types for Page Types
1 parent 779f798 commit bbda712

File tree

11 files changed

+124
-2
lines changed

11 files changed

+124
-2
lines changed

Build/JsonSchema/SchemaSources/page-type.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"basics": {},
1717
"fields": {},
1818
"table": {},
19-
"typeField": {}
19+
"typeField": {},
20+
"allowedRecordTypes": {}
2021
},
2122
"allOf": [
2223
{
@@ -54,6 +55,13 @@
5455
"pattern": "^[0-9]+$"
5556
}
5657
]
58+
},
59+
"allowedRecordTypes": {
60+
"description": "List of allowed records, which may be created on this Page",
61+
"type": "array",
62+
"items": {
63+
"type": "string"
64+
}
5765
}
5866
}
5967
},
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: example/example-page-type
22
typeName: 942
3+
allowedRecordTypes:
4+
- tx_hov_domain_model_notype
35
fields:
46
- identifier: additional_field
57
type: Text

Classes/Definition/ContentType/PageTypeDefinition.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function __construct(
4848
public string $languagePathDescription,
4949
public ?string $group,
5050
public PageIconSet $pageIconSet,
51+
/** @var string[] */
52+
public array $allowedRecordTypes,
5153
) {}
5254

5355
public function getPageIconSet(): PageIconSet

Classes/Definition/Factory/ContentTypeFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ private function createPageTypeDefinition(array $typeDefinition, string $table):
7272
$arguments['table'] = $table;
7373
$iconHideInMenu = ContentTypeIcon::fromArray($typeDefinition['typeIconHideInMenu'] ?? []);
7474
$iconRoot = ContentTypeIcon::fromArray($typeDefinition['typeIconRoot'] ?? []);
75+
$arguments['allowedRecordTypes'] = $typeDefinition['allowedRecordTypes'] ?? [];
7576
$pageIconSet = new PageIconSet($iconHideInMenu, $iconRoot);
7677
$arguments['pageIconSet'] = $pageIconSet;
7778
$pageTypeDefinition = new PageTypeDefinition(...$arguments);

Classes/Definition/Factory/Processing/ProcessedContentType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public function toArray(bool $isRootTable, string $identifier): array
8686
if ($this->contentBlock->getContentType() === ContentType::CONTENT_ELEMENT) {
8787
$contentType['saveAndClose'] = (bool)($yaml['saveAndClose'] ?? false);
8888
}
89+
if ($this->contentBlock->getContentType() === ContentType::PAGE_TYPE) {
90+
$contentType['allowedRecordTypes'] = $this->contentBlock->getYaml()['allowedRecordTypes'] ?? [];
91+
}
8992
return $contentType;
9093
}
9194
}

Classes/Generator/TcaGenerator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,21 @@ protected function processContentElement(ContentTypeInterface $typeDefinition, a
328328

329329
protected function processPageType(ContentTypeInterface $typeDefinition, array $columnsOverrides): array
330330
{
331+
if (!$typeDefinition instanceof PageTypeDefinition) {
332+
throw new \InvalidArgumentException(
333+
'Expected PageTypeDefinition, got ' . get_class($typeDefinition),
334+
1774000611
335+
);
336+
}
331337
$typeDefinitionArray = [
332338
'showitem' => $this->getPageTypeStandardShowItem($typeDefinition->getShowItems(), $typeDefinition->getTypeName()),
333339
];
334340
if ($columnsOverrides !== []) {
335341
$typeDefinitionArray['columnsOverrides'] = $columnsOverrides;
336342
}
343+
if ($typeDefinition->allowedRecordTypes !== []) {
344+
$typeDefinitionArray['allowedRecordTypes'] = $typeDefinition->allowedRecordTypes;
345+
}
337346
return $typeDefinitionArray;
338347
}
339348

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.. include:: /Includes.rst.txt
2+
.. _changelog-2.2:
3+
4+
===
5+
2.2
6+
===
7+
8+
Content Blocks version 2.2 adds compatibility for TYPO3 v14.2.
9+
10+
.. contents::
11+
12+
Feature
13+
=======
14+
15+
Allowed Record Types for Page Types
16+
-----------------------------------
17+
18+
A new option :yaml:`allowedRecordTypes` has been added for Page Types, which
19+
allows you to define a set of Record Types (tables), that should be allowed
20+
on this specific Page Type.
21+
22+
Example: Extending the default allowed values with custom ones.
23+
24+
.. code-block:: yaml
25+
26+
allowedRecordTypes:
27+
- pages
28+
- sys_category
29+
- sys_file_reference
30+
- my_custom_table
31+
32+
Example: Allow all records with an asterisk:
33+
34+
.. code-block:: yaml
35+
36+
allowedRecordTypes:
37+
- *
38+
39+
Read more :ref:`here <confval-page-type-allowedRecordTypes>`.

Documentation/YamlReference/ContentTypes/PageTypes/Index.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,41 @@ Here you can find all :ref:`common root options <yaml_reference_common>`.
6868
* `default`
6969
* `link`
7070
* `special`
71+
72+
.. confval:: allowedRecordTypes
73+
:name: page-type-allowedRecordTypes
74+
:required: false
75+
:type: array<string>
76+
77+
List of allowed Record Types (tables) for this specific Page Type. If defined,
78+
only this list of records can be created on this Page Type. This is also
79+
evaluated when switching a Page Type to another one. Per default the tables
80+
`pages`, `sys_category`, `sys_file_reference` and `sys_file_collection` are
81+
allowed, if not configured otherwise.
82+
83+
.. hint::
84+
85+
If a Record Type ignores Page Type restrictions, then you don't need to
86+
list it here. It will be allowed regardless of this setting.
87+
88+
.. code-block:: yaml
89+
90+
security:
91+
ignorePageTypeRestriction: true
92+
93+
Example: Extending the default allowed values with custom ones.
94+
95+
.. code-block:: yaml
96+
97+
allowedRecordTypes:
98+
- pages
99+
- sys_category
100+
- sys_file_reference
101+
- my_custom_table
102+
103+
Example: Allow all records with an asterisk:
104+
105+
.. code-block:: yaml
106+
107+
allowedRecordTypes:
108+
- *

JsonSchema/page-type.schema.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"basics": {},
1717
"fields": {},
1818
"table": {},
19-
"typeField": {}
19+
"typeField": {},
20+
"allowedRecordTypes": {}
2021
},
2122
"allOf": [
2223
{
@@ -58,6 +59,13 @@
5859
"pattern": "^[0-9]+$"
5960
}
6061
]
62+
},
63+
"allowedRecordTypes": {
64+
"description": "List of allowed records, which may be created on this Page",
65+
"type": "array",
66+
"items": {
67+
"type": "string"
68+
}
6169
}
6270
}
6371
},

Tests/Unit/Generator/TcaGeneratorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,10 @@ public static function pageTypesGenerateCorrectTcaDataProvider(): iterable
16771677
'table' => 'pages',
16781678
'typeField' => 'doktype',
16791679
'typeName' => 1700156757,
1680+
'allowedRecordTypes' => [
1681+
'foo',
1682+
'bar',
1683+
],
16801684
],
16811685
],
16821686
],
@@ -1706,6 +1710,10 @@ public static function pageTypesGenerateCorrectTcaDataProvider(): iterable
17061710
'description' => 'LLL:EXT:my_sitepackage/ContentBlocks/PageTypes/custom-page-type/language/labels.xlf:nav_title.description',
17071711
],
17081712
],
1713+
'allowedRecordTypes' => [
1714+
'foo',
1715+
'bar',
1716+
],
17091717
],
17101718
],
17111719
'columns' => [],

0 commit comments

Comments
 (0)