TYPO3:用副标题扩展ctype文本媒体



我想将子标题添加到ctype"textmedia"(TYPO3 9.5和10.4(。我遵循这个堆叠式的答案:TYPO3 8在文本媒体的后端预览中显示布局选择注册我的Hook

typo3conf/ext/my-extension/Classes/Hooks/PageLayoutView/TextMediaCustomPreviewRenderer.php

然后我添加了子标题

<?php
namespace aaabbbHooksPageLayoutView;

use TYPO3CMSBackendViewPageLayoutViewDrawItemHookInterface;
use TYPO3CMSBackendViewPageLayoutView;
/**
* Contains a preview rendering for the page module of CType="textmedia"
*/
class TextMediaCustomPreviewRenderer implements PageLayoutViewDrawItemHookInterface
{
/**
* Preprocesses the preview rendering of a content element of type "textmedia"
*
* @param TYPO3CMSBackendViewPageLayoutView $parentObject Calling parent object
* @param bool $drawItem Whether to draw the item using the default functionality
* @param string $headerContent Header content
* @param string $subheaderContent Subheader content
* @param string $itemContent Item content
* @param array $row Record row of tt_content
*/
public function preProcess(
PageLayoutView &$parentObject,
&$drawItem,
&$headerContent,
&$subheaderContent,
&$itemContent,
array &$row
) {
if ($row['CType'] === 'textmedia') {
if ($row['bodytext']) {
$itemContent .= $parentObject->linkEditContent($parentObject->renderText($row['bodytext']), $row) . '<br />';
}
if ($row['assets']) {
$itemContent .= $parentObject->linkEditContent($parentObject->getThumbCodeUnlinked($row, 'tt_content', 'assets'), $row) . '<br />';
$fileReferences = BackendUtility::resolveFileReferences('tt_content', 'assets', $row);
if (!empty($fileReferences)) {
$linkedContent = '';
foreach ($fileReferences as $fileReference) {
$description = $fileReference->getDescription();
if ($description !== null && $description !== '') {
$linkedContent .= htmlspecialchars($description) . '<br />';
}
}
$itemContent .= $parentObject->linkEditContent($linkedContent, $row);
unset($linkedContent);
}
}
$drawItem = false;
}
}
}

我得到错误:

Fatal error: Declaration of aaaabbbHooksPageLayoutViewTextMediaCustomPreviewRenderer::preProcess(TYPO3CMSBackendViewPageLayoutView &$parentObject, &$drawItem, &$headerContent, &$subheaderContent, &$itemContent, array &$row) must be compatible with TYPO3CMSBackendViewPageLayoutViewDrawItemHookInterface::preProcess(TYPO3CMSBackendViewPageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row) in /kunden/1111/rp-hosting/2222/333/typo3cms/projekt1/typo3conf/ext/my-sitepackage/Classes/Hooks/PageLayoutView/TextMediaCustomPreviewRenderer.php on line 23

我必须做些什么才能使它与兼容

TYPO3CMSBackendViewPageLayoutViewDrawItemHookInterface::preProcess(TYPO3CMSBackendViewPageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row)

你搞错了。您没有在process()参数中添加子标头。通常,参数必须与它们扩展的类相同。您可以通过在itemContent中添加值来在if ($row['CType'] === 'textmedia') {}中添加子标题

$itemContent .= $row['subheader'];

就我个人而言,我会避免这样做。我的首选是调用StandAlone视图并指定一个模板进行预览。更易于维护和编程。

最新更新