【问题标题】:TYPO3: Extend ctype textmedia with subheaderTYPO3:使用子标题扩展 ctype textmedia
【发布时间】:2020-12-06 16:28:45
【问题描述】:

我想将子标题添加到 ctype 'textmedia' (TYPO3 9.5 & 10.4)。 我遵循了这个stackoverflow答案: TYPO3 8 show layout selection in backend preview for textmedia 注册我的 Hook

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;
        }
    }
}

我得到了错误:

Fatal error: Declaration of aaaa\bbb\Hooks\PageLayoutView\TextMediaCustomPreviewRenderer::preProcess(TYPO3\CMS\Backend\View\PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$subheaderContent, &$itemContent, array &$row) must be compatible with TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface::preProcess(TYPO3\CMS\Backend\View\PageLayoutView &$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

我必须做什么才能使其兼容

TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface::preProcess(TYPO3\CMS\Backend\View\PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row)

【问题讨论】:

    标签: typo3 typo3-9.x


    【解决方案1】:

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

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

    我个人会避免这样做。我的首选是调用 StandAlone View 并分配一个模板进行预览。更易于维护和编程。

    【讨论】:

    • 谢谢,这对我来说是完美的。你能告诉我如何调用 StandAlone View 吗?
    • textmedia 有图片时出现问题 'Class 'aaa\bbb\Hooks\PageLayoutView\BackendUtility' not found |在第 39 行的文件 /xxx/yyy/rp-hosting/ZZZ/aaa/typo3cms/projekt1/typo3conf/ext/my-extension/Classes/Hooks/PageLayoutView/TextMediaCustomPreviewRenderer.php 中引发错误
    • 我可以通过将'BackendUtility.php'添加到文件夹并更改命名空间来解决它
    猜你喜欢
    • 1970-01-01
    • 2014-11-05
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    • 2018-06-23
    • 1970-01-01
    • 2013-08-23
    • 1970-01-01
    相关资源
    最近更新 更多