TYPO3: Extend Ctype Textmedia With Subheader

- 1 answer

I want to add the subheader to the ctype 'textmedia' (TYPO3 9.5 & 10.4). I followed this stackoverflow answer: TYPO3 8 show layout selection in backend preview for textmedia to register my Hook


Then I added the subheader

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,
        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);


            $drawItem = false;

I get the errror:

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

What do I have to do to make it compatible with

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


You got it a bit wrong. You do not add the subheader in your process() arguments. In general, the arguments must be the same as the class that they extend. You can add the subheader inside the if ($row['CType'] === 'textmedia') {} by adding the value in the itemContent

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

Personally i would avoid to do it this way. My preferred choice is to call the StandAlone View and assign a template for preview. Is easier to maintain and program it.