Page Types¶
Global array $GLOBALS[‘PAGES_TYPES’] defines the various types of pages (field: doktype ) the system can handle and what restrictions may apply to them. Here you can define which tables are allowed on a certain page type.
The «default» entry in the $GLOBALS[‘PAGES_TYPES’] array is the «base» for all types, and for every type the entries simply overrides the entries in the «default» type!!
This is the default array as set in EXT:core/ext_tables.php :
$GLOBALS['PAGES_TYPES'] = [ (string)\TYPO3\CMS\Core\Domain\Repository\PageRepository::DOKTYPE_BE_USER_SECTION => [ 'allowedTables' => '*' ], (string)\TYPO3\CMS\Core\Domain\Repository\PageRepository::DOKTYPE_SYSFOLDER => [ // Doktype 254 is a 'Folder' - a general purpose storage folder for whatever you like. // In CMS context it's NOT a viewable page. Can contain any element. 'allowedTables' => '*' ], (string)\TYPO3\CMS\Core\Domain\Repository\PageRepository::DOKTYPE_RECYCLER => [ // Doktype 255 is a recycle-bin. 'allowedTables' => '*' ], 'default' => [ 'allowedTables' => 'pages,sys_category,sys_file_reference,sys_file_collection', 'onlyAllowedTables' => false ], ];
The key used in the array above is the value that will be stored in the doktype field of the «pages» table.
As for other $GLOBALS values, you can view current settings in the backend in System > Configuration (with installed lowlevel system extension).
In TYPO3 versions below 10.4, the doktype was restricted to numbers smaller than 200 if the custom page type should be displayed in the frontend, and larger than 200 when it is just some storage. This limitation no longer exists, so you can choose a number at will.
Each array has the following options available:
Can be «sys» or «web». This is purely informative, as TYPO3 CMS does nothing with that piece of data.
The tables that may reside on pages with that «doktype». Comma-separated list of tables allowed on this page doktype. «*» = all.
Boolean. If set to true, changing the page type will be blocked if the chosen page type contains records that it would not allow.
The options allowedTables and onlyAllowedTables must be set for the default type while the rest can choose as they like.
Types of Pages¶
TYPO3 has predefined a number of pages types as constants in typo3/sysext/core/Classes/Domain/Repository/PageRepository.php .
What role each page type plays and when to use it is explained in more detail in Page types . Some of the page types require additional fields in pages to be filled out:
This type of page creates a redirect to an URL in the frontend. The URL is specified in the field pages.url .
This type of page creates a redirect to another page in the frontend. The shortcut target is specified in the field pages.shortcut , shortcut mode is stored in pages.shortcut_mode .
The mounted page is specified in pages.mount_pid , while display options can be changed with pages.mount_pid_ol .
Create new Page Type¶
The following example adds a new page type called «Archive».
The new page type visible in the TYPO3 backend ¶
The whole code to add a page type is shown below with the according file names above.
The first step is to add the new page type to the global array described above. Then you need to add the icon chosen for the new page type and allow users to drag and drop the new page type to the page tree.
You have to change example in the argument of the anonymous function to your own extension key.
The new page type is added to $GLOBALS[‘PAGES_TYPES’] in ext_tables.php :
(function ($extKey='example') $archiveDoktype = 116; // Add new page type: $GLOBALS['PAGES_TYPES'][$archiveDoktype] = [ 'type' => 'web', 'allowedTables' => '*', ]; >)();
User TSconfig is added and an icon is registed in ext_localconf.php :
(function ($extKey='example') $archiveDoktype = 116; // Provide icon for page tree, list view, . : $iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class); $iconRegistry ->registerIcon( 'apps-pagetree-archive', TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class, [ 'source' => 'EXT:' . $extKey . '/Resources/Public/Icons/Archive.svg', ] ); $iconRegistry ->registerIcon( 'apps-pagetree-archive-contentFromPid', TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class, [ 'source' => 'EXT:' . $extKey . '/Resources/Public/Icons/ArchiveContentFromPid.svg', ] ); // . register other icons in the same way, see below. // Allow backend users to drag and drop the new page type: \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addUserTSConfig( 'options.pageTree.doktypesToShowInNewPageDragArea := addToList(' . $archiveDoktype . ')' ); >)();
Furthermore we need to modify the configuration of «pages» records. As one can modify the pages, we need to add the new doktype as select item and associate it with the configured icon. That’s done in Configuration/TCA/Overrides/pages.php :
(function ($extKey='example', $table='pages') $archiveDoktype = 116; // Add new page type as possible select item: \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem( $table, 'doktype', [ 'LLL:EXT:' . $extKey . '/Resources/Private/Language/locallang.xlf:archive_page_type', $archiveDoktype, 'EXT:' . $extKey . '/Resources/Public/Icons/Archive.svg' ], '1', 'after' ); \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule( $GLOBALS['TCA'][$table], [ // add icon for new page type: 'ctrl' => [ 'typeicon_classes' => [ $archiveDoktype => 'apps-pagetree-archive', $archiveDoktype . '-contentFromPid' => "apps-pagetree-archive-contentFromPid", $archiveDoktype . '-root' => "apps-pagetree-archive-root", $archiveDoktype . '-hideinmenu' => "apps-pagetree-archive-hideinmenu", ], ], // add all page standard fields and tabs to your new page type 'types' => [ (string) $archiveDoktype => [ 'showitem' => $GLOBALS['TCA'][$table]['types'][\TYPO3\CMS\Core\Domain\Repository\PageRepository::DOKTYPE_DEFAULT]['showitem'] ] ] ] ); >)();
As you can see from the example, to make sure you get the correct icons, you can utilize typeicon_classes .
For the following cases you need to configure icons explicitly, otherwise they will automatically fall back to the variant for regular page doktypes.
- Page contains content from another page ( -contentFromPid )
- Page is hidden in navigation ( -hideinmenu )
- Page is site-root ( -root )
Make sure to add the additional icons using the icon registry!
Page 10 php type
While waiting for native support for typed arrays, here are a couple of alternative ways to ensure strong typing of arrays by abusing variadic functions. The performance of these methods is a mystery to the writer and so the responsibility of benchmarking them falls unto the reader.
PHP 5.6 added the splat operator (. ) which is used to unpack arrays to be used as function arguments. PHP 7.0 added scalar type hints. Latter versions of PHP have further improved the type system. With these additions and improvements, it is possible to have a decent support for typed arrays.
function typeArrayNullInt (? int . $arg ): void >
function doSomething (array $ints ): void (function (? int . $arg ) <>)(. $ints );
// Alternatively,
( fn (? int . $arg ) => $arg )(. $ints );
// Or to avoid cluttering memory with too many closures
typeArrayNullInt (. $ints );
function doSomethingElse (? int . $ints ): void /* . */
>
$ints = [ 1 , 2 , 3 , 4 , null ];
doSomething ( $ints );
doSomethingElse (. $ints );
?>
Both methods work with all type declarations. The key idea here is to have the functions throw a runtime error if they encounter a typing violation. The typing method used in doSomethingElse is cleaner of the two but it disallows having any other parameters after the variadic parameter. It also requires the call site to be aware of this typing implementation and unpack the array. The method used in doSomething is messier but it does not require the call site to be aware of the typing method as the unpacking is performed within the function. It is also less ambiguous as the doSomethingElse would also accept n individual parameters where as doSomething only accepts an array. doSomething’s method is also easier to strip away if native typed array support is ever added to PHP. Both of these methods only work for input parameters. An array return value type check would need to take place at the call site.
If strict_types is not enabled, it may be desirable to return the coerced scalar values from the type check function (e.g. floats and strings become integers) to ensure proper typing.
same data type and same value but first function declare as a argument type declaration and return int(7)
and second fucntion declare as a return type declaration but return int(8).
function argument_type_declaration(int $a, int $b) return $a+$b;
>
function return_type_declaration($a,$b) :int return $a+$b;
>