Create new Page Type

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

The new page type visible in the TYPO3 backend

Changes need to be made in several files to create a new page type. Follow the directions below to the end:

Changed in version 12.0

A new PageDoktypeRegistry was introduced replacing the $GLOBALS['PAGES_TYPES'] array. Use the version selector to look up the syntax in the corresponding documentation version for older TYPO3 versions.

  1. Add new page type to PageDoktypeRegistry

    The new page type has to be added to the \TYPO3\CMS\Core\DataHandling\PageDoktypeRegistry . TYPO3 uses this registry internally to only allow specific tables to be inserted on that page type. This registry will not add or modify any TCA. In example below all kind of tables (*) are allowed to be inserted on the new page type.

    The new page type is added to the PageDoktypeRegistry in ext_tables.php:

    EXT:examples/ext_tables.php
    <?php
    
    use TYPO3\CMS\Core\DataHandling\PageDoktypeRegistry;
    use TYPO3\CMS\Core\Utility\GeneralUtility;
    
    defined('TYPO3') or die();
    
    // Define a new doktype
    $customPageDoktype = 116;
    // Add page type to system
    $dokTypeRegistry = GeneralUtility::makeInstance(PageDoktypeRegistry::class);
    $dokTypeRegistry->add(
        $customPageDoktype,
        [
            'allowedTables' => '*',
        ],
    );
    
    Copied!
  2. Add an icon chosen for the new page type

    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.

    We need to add the following user TSconfig to all users, so that the new page type is displayed in the wizard:

    EXT:examples/Configuration/TsConfig/User/UserConfiguration.tsconfig
    options.pageTree.doktypesToShowInNewPageDragArea := addToList(116)
    
    Copied!

    You can load the file like this:

    EXT:examples/ext_localconf.php
    <?php
    
    use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
    
    defined('TYPO3') or die();
    
    // Add custom doktype to the page tree toolbar
    ExtensionManagementUtility::addUserTSConfig(
        "@import 'EXT:examples/Configuration/TsConfig/User/*.tsconfig'",
    );
    
    Copied!

    The icon is registered in Configuration/Icons.php:

    EXT:examples/Configuration/Icons.php
    <?php
    
    use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider;
    
    return [
        'tx-examples-archive-page' => [
            'provider' => SvgIconProvider::class,
            'source' => 'EXT:examples/Resources/Public/Images/ArchivePage.svg',
        ],
    ];
    
    Copied!

    It is possible to define additional type icons for special case pages:

    • Page contains content from another page <doktype>-contentFromPid, For example: $GLOBALS['TCA']['pages']['ctrl']['typeicon_classes']['116-contentFromPid'] .
    • Page is hidden in navigation <doktype>-hideinmenu For example: $GLOBALS['TCA']['pages']['ctrl']['typeicon_classes']['116-hideinmenu'] .
    • Page is the root of the site <doktype>-root For example: $GLOBALS['TCA']['pages']['ctrl']['typeicon_classes']['116-root'] .
  3. Add new page type to doktype selector

    We need to modify the configuration of page records. As one can modify the pages, we need to add the new doktype as a select option and associate it with the configured icon. That is done in Configuration/TCA/Overrides/pages.php:

    EXT:examples/Configuration/TCA/Overrides/pages.php
    <?php
    
    defined('TYPO3') or die();
    
    // encapsulate all locally defined variables
    (function () {
        // SAME as registered in ext_tables.php
        $customPageDoktype = 116;
        $customIconClass = 'tx-examples-archive-page';
    
        // Add the new doktype to the page type selector
        \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
            'pages',
            'doktype',
            [
                'label' => 'LLL:EXT:examples/Resources/Private/Language/locallang.xlf:archive_page_type',
                'value' => $customPageDoktype,
                'icon'  => $customIconClass,
                'group' => 'special',
            ],
        );
    
        // Add the icon to the icon class configuration
        $GLOBALS['TCA']['pages']['ctrl']['typeicon_classes'][$customPageDoktype] = $customIconClass;
    })();
    
    Copied!

    As you can see from the example, to make sure you get the correct icons, you can utilize typeicon_classes.

  4. Define your own columns for new page type

    By default the new page type will render all columns of default page type (DEFAULT (1)). If you want to chose your own columns you have to copy over all columns from default page type:

    EXT:examples/Configuration/TCA/Overrides/pages.php
    <?php
    
    defined('TYPO3') or die();
    
    // encapsulate all locally defined variables
    (function () {
        // ...code from previous example
    
        // Copy over all columns from default page type to allow TCA modifications
        // with f.e. ExtensionManagementUtility::addToAllTCAtypes()
        $GLOBALS['TCA']['pages']['types'][116] = $GLOBALS['TCA']['pages']['types'][1];
    })();
    
    Copied!

    Now you can modify TCA with Core API like ExtensionManagementUtility::addToAllTCAtypes();

Further Information