Typo3 类型3:使用副标题扩展ctype textmedia
我想在ctype“textmedia”(TYPO3 9.5和10.4)中添加副标题。 我的回答如下: 登记我的钩子Typo3 类型3:使用副标题扩展ctype textmedia,typo3,typo3-9.x,Typo3,Typo3 9.x,我想在ctype“textmedia”(TYPO3 9.5和10.4)中添加副标题。 我的回答如下: 登记我的钩子 typo3conf/ext/my-extension/Classes/Hooks/PageLayoutView/TextMediaCustomPreviewRenderer.php 然后我加上了副标题 <?php namespace aaa\bbb\Hooks\PageLayoutView; use \TYPO3\CMS\Backend\View\PageLayo
typo3conf/ext/my-extension/Classes/Hooks/PageLayoutView/TextMediaCustomPreviewRenderer.php
然后我加上了副标题
<?php
namespace aaa\bbb\Hooks\PageLayoutView;
use \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
use \TYPO3\CMS\Backend\View\PageLayoutView;
/**
* 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 \TYPO3\CMS\Backend\View\PageLayoutView $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;
}
}
}
我必须做些什么才能使它与
TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface::preProcess(TYPO3\CMS\Backend\View\PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row)
你弄错了。在
process()
参数中不添加副标题。通常,参数必须与其扩展的类相同。通过在itemContent
$itemContent .= $row['subheader'];
就我个人而言,我会避免这样做。我的首选方法是调用独立视图并为预览指定模板。更易于维护和编程。您弄错了一点。在
process()
参数中不添加副标题。通常,参数必须与其扩展的类相同。通过在itemContent
$itemContent .= $row['subheader'];
就我个人而言,我会避免这样做。我的首选方法是调用独立视图并为预览指定模板。更易于维护和编程。谢谢,这对我来说太完美了。你能给我一个如何调用独立视图的提示吗?当textmedia在第39行的图片“Class”aaa\bbb\Hooks\PageLayoutView\BackendUtility“未找到”时,我遇到了一个问题,在/xxx/yyyy/rp hosting/ZZZ/aaa/typo3cms/projekt1/typo3conf/ext/my extension/Classes/Hooks/PageLayoutView/TextMediaCustomPreviewRenderer.php中抛出了一个错误,我可以解决通过在文件夹中添加'BackendUtility.php'并更改名称空间来实现。谢谢,这对我来说太完美了。你能给我一个如何调用独立视图的提示吗?当textmedia在第39行的图片“Class”aaa\bbb\Hooks\PageLayoutView\BackendUtility“未找到”时,我遇到了一个问题,在/xxx/yyyy/rp hosting/ZZZ/aaa/typo3cms/projekt1/typo3conf/ext/my extension/Classes/Hooks/PageLayoutView/TextMediaCustomPreviewRenderer.php中抛出了一个错误,我可以解决通过将“BackendUtility.php”添加到文件夹并更改名称空间来实现