[FEATURE] Show tt_content preview in page module via Fluid 62/42962/4
authorBenjamin Mack <benni@typo3.org>
Tue, 1 Sep 2015 17:53:21 +0000 (19:53 +0200)
committerAlexander Opitz <opitz.alexander@googlemail.com>
Wed, 9 Sep 2015 06:50:54 +0000 (08:50 +0200)
A new option via TSconfig allows to render tt_content elements via Fluid
in the Backend.

Example:
mod.web_layout.tt_content.preview.media = EXT:site_mysite/Resources/Private/Templates/Preview/Media.html

All values from the tt_content record are available as content elements.

Resolves: #69459
Releases: master
Change-Id: Iceee2f4621ce24b59f6006db6a67db69b631e332
Reviewed-on: http://review.typo3.org/42962
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
typo3/sysext/backend/Classes/View/PageLayoutView.php
typo3/sysext/core/Documentation/Changelog/master/Feature-69459-ShowTt_contentPreviewInPageModuleViaFluid.rst [new file with mode: 0644]

index 208901d..7843439 100644 (file)
@@ -26,6 +26,8 @@ use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Type\Bitmask\Permission;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Versioning\VersionState;
+use TYPO3\CMS\Extbase\Service\FlexFormService;
+use TYPO3\CMS\Fluid\View\StandaloneView;
 
 /**
  * Child class for the Web > Page module
@@ -1344,6 +1346,36 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
                                $hookObject->preProcess($this, $drawItem, $outHeader, $out, $row);
                        }
                }
+
+               // If the previous hook did not render something,
+               // then check if a Fluid-based preview template was defined for this CType
+               // and render it via Fluid. Possible option:
+               // mod.web_layout.tt_content.preview.media = EXT:site_mysite/Resources/Private/Templates/Preview/Media.html
+               if ($drawItem) {
+                       $tsConfig = BackendUtility::getModTSconfig($row['pid'], 'mod.web_layout.tt_content.preview');
+                       if (!empty($tsConfig['properties'][$row['CType']])) {
+                               $fluidTemplateFile = $tsConfig['properties'][$row['CType']];
+                               $fluidTemplateFile = GeneralUtility::getFileAbsFileName($fluidTemplateFile);
+                               if ($fluidTemplateFile) {
+                                       try {
+                                               /** @var StandaloneView $view */
+                                               $view = GeneralUtility::makeInstance(StandaloneView::class);
+                                               $view->setTemplatePathAndFilename($fluidTemplateFile);
+                                               $view->assignMultiple($row);
+                                               if (!empty($row['pi_flexform'])) {
+                                                       /** @var FlexFormService $flexFormService */
+                                                       $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
+                                                       $view->assign('pi_flexform_transformed', $flexFormService->convertFlexFormContentToArray($row['pi_flexform']));
+                                               }
+                                               $out = $view->render();
+                                               $drawItem = FALSE;
+                                       } catch (\Exception $e) {
+                                               // Catch any exception to avoid breaking the view
+                                       }
+                               }
+                       }
+               }
+
                // Draw preview of the item depending on its CType (if not disabled by previous hook):
                if ($drawItem) {
                        switch ($row['CType']) {
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-69459-ShowTt_contentPreviewInPageModuleViaFluid.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-69459-ShowTt_contentPreviewInPageModuleViaFluid.rst
new file mode 100644 (file)
index 0000000..8e6ebe4
--- /dev/null
@@ -0,0 +1,28 @@
+==================================================================
+Feature: #69459 - Show tt_content preview in page module via Fluid
+==================================================================
+
+Description
+===========
+
+A new PageTSconfig option allows to render a preview of a single content element in the Backend via Fluid.
+
+The following option allows to override the default output of a content element via PageTSconfig:
+
+.. code-block:: typoscript
+
+       mod.web_layout.tt_content.preview.media = EXT:site_mysite/Resources/Private/Templates/Preview/Media.html
+
+All content elements with CType "media" will then be rendered by the Fluid Template which can be rendered like:
+
+.. code-block:: html
+
+       <h4>{header}</h4>
+       <f:format.crop length="200">{bodytext}</f:format.crop>
+
+All properties of the tt_content record are available in the template directly.
+Any data of the flexform field ``pi_flexform`` is available with the property ``pi_flexform_transformed`` as an array.
+
+.. note::
+
+If a PHP hook already is set to render the element, it will take precedence over the Fluid-based preview.
\ No newline at end of file