Last active
January 30, 2020 19:17
-
-
Save uberboom/553ce67e033b65732cbd to your computer and use it in GitHub Desktop.
TYPO3: Render a backend preview of custom content elements (TYPO3 CMS 6.2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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