Skip to content

Instantly share code, notes, and snippets.

@jmverges
Forked from Torsten85/PagePreviewRenderer.php
Created November 26, 2015 09:03
Show Gist options
  • Save jmverges/9893fd6ee85c069c9687 to your computer and use it in GitHub Desktop.
Save jmverges/9893fd6ee85c069c9687 to your computer and use it in GitHub Desktop.
Showing the preview section of fluidpages.
<?php
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'][] = \My\Extension\Hooks\PagePreviewRenderer::class . '->render';
<?php
namespace My\Extension\Hooks;
use FluidTYPO3\Fluidpages\Provider\PageProvider;
use TYPO3\CMS\Backend\Controller\PageLayoutController;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use FluidTYPO3\Flux\Service\WorkspacesAwareRecordService;
use FluidTYPO3\Flux\View\PreviewView;
class PagePreviewRenderer {
/**
* @param array $params
* @param PageLayoutController $pageLayoutController
* @return string
*/
public function render(array $params, PageLayoutController $pageLayoutController) {
/** @var ObjectManager $objectManager */
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var WorkspacesAwareRecordService $recordService */
$recordService = $objectManager->get(WorkspacesAwareRecordService::class);
/** @var PageProvider $pageProvider */
$pageProvider = $objectManager->get(PageProvider::class);
$row = $recordService->getSingle('pages', '*', $pageLayoutController->id);
$form = $pageProvider->getForm($row);
#prevent rendering of the grid twice
$form->setOption(PreviewView::OPTION_PREVIEW, array(
PreviewView::OPTION_MODE => PreviewView::MODE_NONE
));
list($previewHeader, $previewContent, $continueDrawing) = $pageProvider->getPreview($row);
return $previewContent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment