PHP code example of digitalwerk / typo3-element-registry-cli
1. Go to this page and download the library: Download digitalwerk/typo3-element-registry-cli library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
digitalwerk / typo3-element-registry-cli example snippets
declare(strict_types=1);
namespace Vendor\Extension\Utility;
use TYPO3\CMS\Frontend\Page\PageRepository;
/**
* Class PageTypeUtility
* @package Vendor\Extension\Utility
*/
class PageTypeUtility
{
/**
* Get Doktype icon identifier
* @param int $doktype
* @return string
*/
public static function getDoktypeIconIdentifier(int $doktype): string
{
return "{extension}-{$doktype}";
}
/**
* Adds new page type
* @param int $doktype
* @throws \Exception
*/
public static function addPageDoktype(int $doktype)
{
if (array_key_exists($doktype, $GLOBALS['PAGES_TYPES'])) {
throw new \Exception("Page type with doktype: {$doktype} already exists!", 1485421360);
}
// Add new page type
$GLOBALS['PAGES_TYPES'][$doktype] = [
'type' => 'web',
'allowedTables' => '*',
];
// Provide icon for page tree, list view, ... :
$iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Imaging\IconRegistry::class
);
$iconIdentifier = self::getDoktypeIconIdentifier($doktype);
$iconRegistry->registerIcon(
$iconIdentifier,
\TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
['source' => "EXT:{extension}/Resources/Public/Icons/{$iconIdentifier}.svg"]
);
$iconRegistry->registerIcon(
$iconIdentifier.'-not-in-menu',
\TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
['source' => "EXT:{extension}/Resources/Public/Icons/{$iconIdentifier}-not-in-menu.svg"]
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addUserTSConfig(
'options.pageTree.doktypesToShowInNewPageDragArea := addToList(' . $doktype . ')'
);
}
/**
* Adds new doktype to TCA select
* @param int $doktype
* @param string $position
*/
public static function addTcaDoktype(int $doktype, string $position = '')
{
$iconIdentifier = self::getDoktypeIconIdentifier($doktype);
if ($position !== '') {
list($relativePosition, $relativeToField) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(':', $position);
} else {
$relativePosition = 'after';
$relativeToField = '1';
}
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
'pages',
'doktype',
[
"LLL:EXT:{extension}/Resources/Private/Language/locallang_db.xlf:page.type.{$doktype}.label",
$doktype,
$iconIdentifier,
],
$relativeToField,
$relativePosition
);
\TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule(
$GLOBALS['TCA']['pages'],
[
'ctrl' => [
'typeicon_classes' => [
$doktype => $iconIdentifier,
$doktype.'-hideinmenu' => "{$iconIdentifier}-not-in-menu",
],
],
'types' => [
$doktype => $GLOBALS['TCA']['pages']['types'][(string)PageRepository::DOKTYPE_DEFAULT],
],
]
);
}
}