在typo3中配置后端字段

问题描述 投票:0回答:1

我正在使用Typo3 V8我需要在BE中添加一些额外的字段,这样就创建了一个扩展,允许我添加额外的字段,它工作正常。

我的问题是所有页面都显示所有字段,某些字段不应出现在所有页面中

例如我的主页包含一个滑块,因此在BE中我有用于上传图像的字段,但在其他页面中我不需要显示这些字段。

typo3 typoscript
1个回答
2
投票

您可以添加一个具有额外字段的特殊doktype。

我们假设它将是doktype 163,然后在ext_localconf.php中添加:

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addUserTSConfig(
  'options.pageTree.doktypesToShowInNewPageDragArea := addToList(163)'
);

将其添加到pagetree上方的页面类型列表中。

在同一个文件中注册doktype的图标:

\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
  \TYPO3\CMS\Core\Imaging\IconRegistry::class
)->registerIcon(
  'apps-pagetree-mytype',
  TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
  [
    'source' => 'EXT:' . $extKey . '/Resources/Public/Icons/Mytype.svg',
  ]
);

(当然你需要添加你的svg图像或使用不同的图标提供程序来注册位图)

Configuration/TCA/Overrides/pages.php放:

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
  'pages',
  'doktype',
  [
    'Page type name',
    163,
    'apps-pagetree-mytype'
  ],
  '1',
  'after'
);

$GLOBALS['TCA']['pages']['ctrl']['typeicon_classes'][163] = 'apps-pagetree-mytype';

不是通过调用\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes()添加自定义字段,而是添加它们:

$GLOBALS['TCA']['pages']['types'][163]['showitem'] =
  $GLOBALS['TCA']['pages']['types'][\TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT]['showitem']
  . 'the list with your new fields';

这基本上复制了默认页面类型中的字段,并将它们添加到您的自定义doktype中。

当然,在XLIFF文件中使用页面类型的名称并在代码中将doktype编号作为常量更好,但这是您要添加的。

根据doktype,您可以呈现新字段的所有内容。希望这是添加页面类型的完整设置列表:-)

© www.soinside.com 2019 - 2024. All rights reserved.