Skip to content

Instantly share code, notes, and snippets.

@Merec
Forked from uberboom/PageLayoutView.php
Last active September 16, 2021 08:55
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Merec/1f042b6dadd7d9ca8713 to your computer and use it in GitHub Desktop.
Save Merec/1f042b6dadd7d9ca8713 to your computer and use it in GitHub Desktop.
TYPO3: Render a backend preview of custom content elements (TYPO3 CMS 6.2)
<?php
// configure your custom content elements here
// ...
// add hook
// http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Hooks/Configuration/Index.html#hooks-core
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'][$_EXTKEY] = t3lib_extMgm::extPath($_EXTKEY) . 'Classes/Hooks/PageLayoutView.php:\Your\Extension\Namespace\Hooks\PageLayoutView';
<?php
namespace Your\Extension\Namespace\Hooks;
class PageLayoutView implements \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface
{
/**
* Preprocesses the preview rendering of a content element.
*
* @param \TYPO3\CMS\Backend\View\PageLayoutView $parentObject Calling parent object
* @param boolean $drawItem Whether to draw the item using the default functionalities
* @param string $headerContent Header content
* @param string $itemContent Item content
* @param array $row Record row of tt_content
* @return void
*/
public function preProcess(\TYPO3\CMS\Backend\View\PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row)
{
switch ($row['CType']) {
// sample
case 'yourextension_quote':
$drawItem = false;
$headerContent = '<strong>' . $parentObject->CType_labels[$row['CType']] . '</strong><br/>';
$itemContent = $row['tx_yourextension_quote'] . '<br/>';
break;
// sample using an extbase repository
case 'yourextension_teaser':
$drawItem = false;
$headerContent = '<strong>' . $parentObject->CType_labels[$row['CType']] . '</strong><br/>';
$extbaseObjectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$yourRepository = $extbaseObjectManager->get('\Your\Extension\Namespace\Domain\Repository\YourRepository');
$elements = $yourRepository->findByUid($row['uid']);
foreach ($elements as $element) {
$itemContent .= $element->getTitle() . '<br/>';
}
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment