digitalwerk / typo3-element-registry-cli
用于注册 Typo3 内容元素、页面类型或插件的辅助工具。
12.0.1
2023-06-23 09:59 UTC
Requires
- php: >=7.4
- digitalwerk/content_element_registry: >=11 <12.9.9
- typo3/cms-core: >=11 <12.9.9
Replaces
- digitalwerk/typo3_element_registry_cli: 12.0.1
README
使用 CLI 创建新元素(如内容元素、页面类型等)。
安装
通过 composer 安装扩展 composer require digitalwerk/typo3-element-registry-cli
并在扩展模块中激活。
配置
扩展设置
激活扩展后,您需要填写扩展设置。
常规
- 供应商
内容元素
- classExtend(可选)
- modelExtend(可选)
- classTemplatePath(可选)
- modelTemplatePath(可选)
- templateTemplatePath(可选)
页面类型
- typoScriptConstantsPath(必需)
- typoScript 常量路径(例如:EXT:{extension}/Configuration/TypoScript/constants.typoscript)
- utilityPath
- 工具类路径
- 工具类必须包含 addPageDoktype(int $doktype) 静态函数
<?php 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], ], ] ); } }
- modelExtend(可选)
- modelTemplatePath(可选)
插件
- controllerExtend(可选)
记录
- modelTemplatePath(可选)
- tcaTemplatePath(可选)
标记
/** 已注册图标 */
- 位置:EXT:{extension}/ext_localconf.php
/** 插件配置 */
- 位置:EXT:{extension}/ext_localconf.php
/** 页面类型 */
- 位置:EXT:{extension}/Configuration/Extbase/Persistence/Classes.php
/** 添加页面 doktypes */
- 位置:EXT:{extension}/ext_tables.php
用法
命令
- dw:make:contentElement
- dw:make:pageType
- dw:make:record
- dw:make:plugin