Attention

TYPO3 v8 has reached its end-of-life March 31st, 2020 and is not maintained by the community anymore. Looking for a stable version? Use the version switch on the top left.

There is no further ELTS support. It is recommended that you upgrade your project and use a supported version of TYPO3.

Page types

Global array $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.

Note

The "default" entry in the $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'] = array(
 (string) \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_LINK => array(
 ),
 (string) \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SHORTCUT => array(
 ),
 // ...
 //  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.
 (string) \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SYSFOLDER => array(
     'type' => 'sys',
     'allowedTables' => '*'
 ),
 // ...
 'default' => array(
     'type' => 'web',
     'allowedTables' => 'pages',
     'onlyAllowedTables' => '0'
 )
);

The key used in the array above is the value that will be stored in the doktype field of the "pages" table.

Important

The choice of value for the doktype is critical. If you want your custom page type to be displayed in the frontend, you must make sure to choose a doktype smaller than 200. If it's supposed to be just some storage, choose a doktype larger than 200.

Each array has the following options available:

Key

Description

type

Can be "sys" or "web". This is purely informative, as TYPO3 CMS does nothing with that piece of data.

allowedTables

The tables that may reside on pages with that "doktype". Comma-separated list of tables allowed on this page doktype. "*" = all.

onlyAllowedTables

Boolean. If set to true, changing the page type will be blocked if the chosen page type contains records that it would not allow.

Note

All above options must be set for the default type while the rest can choose as they like.

Create new Page Type

The following example adds a new page type called "Archive".

The new page type in action

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. Note: You have to change 'example' in the call_user_func() method to your own extension key.

All the changes are applied in ext_tables.php:

call_user_func(
    function ($extKey) {
        $archiveDoktype = 116;

        // Add new page type:
        $GLOBALS['PAGES_TYPES'][$archiveDoktype] = [
            'type' => 'web',
            'allowedTables' => '*',
        ];

        // Provide icon for page tree, list view, ... :
        \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class)
            ->registerIcon(
                'apps-pagetree-archive',
                TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
                [
                    'source' => 'EXT:' . $extKey . '/Resources/Public/Icons/Archive.svg',
                ]
            );

        // Allow backend users to drag and drop the new page type:
        \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addUserTSConfig(
            'options.pageTree.doktypesToShowInNewPageDragArea := addToList(' . $archiveDoktype . ')'
        );
    },
    'example'
);

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:

call_user_func(
    function ($extKey, $table) {
        $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/Images/Archive.svg'
            ],
            '1',
            'after'
        );

        // Add icon for new page type:
        \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule(
            $GLOBALS['TCA']['pages'],
            [
                'ctrl' => [
                    'typeicon_classes' => [
                        $archiveDoktype => 'apps-pagetree-archive',
                    ],
                ],
            ]
        );
    },
    'example',
    'pages'
);

The same must be done with the "pages_language_overlay", so that the new page type can also be translated Configuration/TCA/Overrides/pages_language_overlay.php:

// Also add the new doktype to the page language overlays type selector (so that translations can inherit the same type)
call_user_func(
    function ($extKey, $table) {
        $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/Images/Archive.svg'
            ],
            '1',
            'after'
        );
    },
    'example',
    'pages_language_overlay'
);