[FEATURE] Ease previewing custom record data in workspace module 46/31146/4
authorOliver Hader <oliver@typo3.org>
Wed, 25 Jun 2014 16:04:02 +0000 (18:04 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Fri, 18 Sep 2015 17:48:48 +0000 (19:48 +0200)
Currently only pages, pages_language_overlay and tt_content have
the possibility to open a preview in the website frontend.
A hook needs to be used to open the preview for custom records
(since possibly the location of the rendering plugin and its
page needs to be resolved).

To ease that behaviour a new Page TSconfig setting is added:
options.workspaces.previewPageId

Possibilities:
* options.workspaces.previewPageId = 123
* options.workspaces.previewPageId = field:pid
* options.workspaces.previewPageId.tx_myext_table = 123
* options.workspaces.previewPageId.tx_myext_table = field:pid

Resolves: #59144
Releases: master
Change-Id: I44fffa6fffb1ccc8af79e6dea48415cdf281cb01
Reviewed-on: http://review.typo3.org/31146
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Feature-59144-PageTSconfigWorkspacePreview [new file with mode: 0644]
typo3/sysext/workspaces/Classes/Service/WorkspaceService.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-59144-PageTSconfigWorkspacePreview b/typo3/sysext/core/Documentation/Changelog/master/Feature-59144-PageTSconfigWorkspacePreview
new file mode 100644 (file)
index 0000000..15d792b
--- /dev/null
@@ -0,0 +1,21 @@
+==================================================================
+Feature: #59144 - Previewing workspace records using Page TSconfig
+==================================================================
+
+Description
+===========
+
+Per default TYPO3 only creates preview links for the tables tt_content, pages
+and pages_language_overlay. To avoid utilizing a hook for each table, creating
+preview links can be triggered using Page TSconfig.
+
+.. code-block:: TypoScript
+
+       # Using page 123 for previewing workspaces records (in general)
+       options.workspaces.previewPageId = 123
+       # Using the pid field of each record for previewing (in general)
+       options.workspaces.previewPageId = field:pid
+       # Using page 123 for previewing workspaces records (for table tx_myext_table)
+       options.workspaces.previewPageId.tx_myext_table = 123
+       # Using the pid field of each record for previewing (or table tx_myext_table)
+       options.workspaces.previewPageId.tx_myext_table = field:pid
\ No newline at end of file
index 8afebf6..8ae6cbc 100644 (file)
@@ -530,43 +530,64 @@ class WorkspaceService implements SingletonInterface {
         * @return string
         */
        static public function viewSingleRecord($table, $uid, array $liveRecord = NULL, array $versionRecord = NULL) {
-               $viewUrl = '';
-
-               if ($table == 'pages') {
-                       $viewUrl = BackendUtility::viewOnClick(BackendUtility::getLiveVersionIdOfRecord('pages', $uid));
-               } elseif ($table === 'pages_language_overlay' || $table === 'tt_content') {
-                       if ($liveRecord === NULL) {
-                               $liveRecord = BackendUtility::getLiveVersionOfRecord($table, $uid);
-                       }
-                       if ($versionRecord === NULL) {
-                               $versionRecord = BackendUtility::getRecord($table, $uid);
-                       }
-                       if (VersionState::cast($versionRecord['t3ver_state'])->equals(VersionState::MOVE_POINTER)) {
-                               $movePlaceholder = BackendUtility::getMovePlaceholder($table, $liveRecord['uid'], 'pid');
-                       }
+               if ($table === 'pages') {
+                       return BackendUtility::viewOnClick(BackendUtility::getLiveVersionIdOfRecord('pages', $uid));
+               }
 
-                       $previewPageId = (empty($movePlaceholder['pid']) ? $liveRecord['pid'] : $movePlaceholder['pid']);
-                       $additionalParameters = '&tx_workspaces_web_workspacesworkspaces[previewWS]=' . $versionRecord['t3ver_wsid'];
+               if ($liveRecord === NULL) {
+                       $liveRecord = BackendUtility::getLiveVersionOfRecord($table, $uid);
+               }
+               if ($versionRecord === NULL) {
+                       $versionRecord = BackendUtility::getRecord($table, $uid);
+               }
+               if (VersionState::cast($versionRecord['t3ver_state'])->equals(VersionState::MOVE_POINTER)) {
+                       $movePlaceholder = BackendUtility::getMovePlaceholder($table, $liveRecord['uid'], 'pid');
+               }
 
+               // Directly use pid value and consider move placeholders
+               $previewPageId = (empty($movePlaceholder['pid']) ? $liveRecord['pid'] : $movePlaceholder['pid']);
+               $additionalParameters = '&tx_workspaces_web_workspacesworkspaces[previewWS]=' . $versionRecord['t3ver_wsid'];
+               // Add language parameter if record is a localization
+               if (BackendUtility::isTableLocalizable($table)) {
                        $languageField = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
                        if ($versionRecord[$languageField] > 0) {
                                $additionalParameters .= '&L=' . $versionRecord[$languageField];
                        }
+               }
+
+               $pageTsConfig = BackendUtility::getPagesTSconfig($previewPageId);
+               $viewUrl = '';
 
+               // Directly use determined direct page id
+               if ($table === 'pages_language_overlay' || $table === 'tt_content') {
                        $viewUrl = BackendUtility::viewOnClick($previewPageId, '', '', '', '', $additionalParameters);
-               } else {
-                       if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['workspaces']['viewSingleRecord'])) {
-                               $_params = array(
-                                       'table' => $table,
-                                       'uid' => $uid,
-                                       'record' => $liveRecord,
-                                       'liveRecord' => $liveRecord,
-                                       'versionRecord' => $versionRecord,
-                               );
-                               $_funcRef = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['workspaces']['viewSingleRecord'];
-                               $null = NULL;
-                               $viewUrl = GeneralUtility::callUserFunction($_funcRef, $_params, $null);
+               // Analyze Page TSconfig options.workspaces.previewPageId
+               } elseif (!empty($pageTsConfig['options.']['workspaces.']['previewPageId.'][$table]) || !empty($pageTsConfig['options.']['workspaces.']['previewPageId'])) {
+                       if (!empty($pageTsConfig['options.']['workspaces.']['previewPageId.'][$table])) {
+                               $previewConfiguration = $pageTsConfig['options.']['workspaces.']['previewPageId.'][$table];
+                       } else {
+                               $previewConfiguration = $pageTsConfig['options.']['workspaces.']['previewPageId'];
                        }
+                       // Extract possible settings (e.g. "field:pid")
+                       list($previewKey, $previewValue) = explode(':', $previewConfiguration, 2);
+                       if ($previewKey === 'field') {
+                               $previewPageId = (int)$liveRecord[$previewValue];
+                       } else {
+                               $previewPageId = (int)$previewConfiguration;
+                       }
+                       $viewUrl = BackendUtility::viewOnClick($previewPageId, '', '', '', '', $additionalParameters);
+               // Call user function to render the single record view
+               } elseif (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['workspaces']['viewSingleRecord'])) {
+                       $_params = array(
+                               'table' => $table,
+                               'uid' => $uid,
+                               'record' => $liveRecord,
+                               'liveRecord' => $liveRecord,
+                               'versionRecord' => $versionRecord,
+                       );
+                       $_funcRef = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['workspaces']['viewSingleRecord'];
+                       $null = NULL;
+                       $viewUrl = GeneralUtility::callUserFunction($_funcRef, $_params, $null);
                }
 
                return $viewUrl;