Create new Page Type

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

../../_images/NewPageType.png

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.

The first step is to add the new page type to the \TYPO3\CMS\Core\DataHandling\PageDoktypeRegistry. 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.

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,
    [
        'type' => 'web',
        'allowedTables' => '*',
    ]
);

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)

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'"
);

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',
    ],
];

Furthermore we need to modify the configuration of page records. As one can modify the pages, we need to add the new doktype as an 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;
})();

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

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

  • Page contains content from another page <doktype>-mountpoint, For example: $GLOBALS['TCA']['pages']['ctrl']['typeicon_classes']['116-mountpoint'].

  • 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'].

Note

Make sure to add the additional icons using the Icon API!