[BUGFIX] Make it possible to add cHash to preview links 64/50264/21
authorGeorg Ringer <georg.ringer@gmail.com>
Tue, 18 Oct 2016 13:54:39 +0000 (15:54 +0200)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Wed, 3 Jan 2018 19:19:18 +0000 (20:19 +0100)
It must be possible to generate preview URLs with a cHash, e.g. to
display records using Extbase which enforces cHash usage.

Introduce a new option "useCacheHash" which triggers cHash calculation.
If not specified, the "no_cache" parameter is added just like before.

Resolves: #78336
Resolves: #81297
Releases: master, 8.7
Change-Id: I225e2b8b4355022e7b4f6866c989b707e526e389
Reviewed-on: https://review.typo3.org/50264
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Richard Haeser <richard@maxserv.com>
Tested-by: Richard Haeser <richard@maxserv.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
typo3/sysext/backend/Classes/Controller/EditDocumentController.php
typo3/sysext/core/Documentation/Changelog/8.7.x/Important-78336-GeneratePreviewLinksWithAChash.rst [new file with mode: 0644]

index 5ee378e..ba4dd4d 100644 (file)
@@ -41,6 +41,7 @@ use TYPO3\CMS\Core\Utility\HttpUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
+use TYPO3\CMS\Frontend\Page\CacheHashCalculator;
 use TYPO3\CMS\Frontend\Page\PageRepository;
 
 /**
@@ -816,9 +817,7 @@ class EditDocumentController
             }
         }
 
-        $linkParameters = [
-            'no_cache' => 1,
-        ];
+        $linkParameters = [];
 
         // language handling
         $languageField = $GLOBALS['TCA'][$table]['ctrl']['languageField'] ?? '';
@@ -855,11 +854,19 @@ class EditDocumentController
             $linkParameters = array_replace($linkParameters, $additionalGetParameters);
         }
 
-        // anchor with uid of content element]
-        $anchorSection = $table === 'tt_content' ? '#c' . $recordId : '';
+        if (!empty($previewConfiguration['useCacheHash'])) {
+            /** @var CacheHashCalculator */
+            $cacheHashCalculator = GeneralUtility::makeInstance(CacheHashCalculator::class);
+            $fullLinkParameters = GeneralUtility::implodeArrayForUrl('', array_merge($linkParameters, ['id' => $previewPageId]));
+            $cacheHashParameters = $cacheHashCalculator->getRelevantParameters($fullLinkParameters);
+            $linkParameters['cHash'] = $cacheHashCalculator->calculateCacheHash($cacheHashParameters);
+        } else {
+            $linkParameters['no_cache'] = 1;
+        }
 
         $this->popViewId = $previewPageId;
         $this->popViewId_addParams = GeneralUtility::implodeArrayForUrl('', $linkParameters, '', false, true);
+        $anchorSection = $table === 'tt_content' ? '#c' . $recordId : '';
 
         $previewPageRootline = BackendUtility::BEgetRootLine($this->popViewId);
         return '
diff --git a/typo3/sysext/core/Documentation/Changelog/8.7.x/Important-78336-GeneratePreviewLinksWithAChash.rst b/typo3/sysext/core/Documentation/Changelog/8.7.x/Important-78336-GeneratePreviewLinksWithAChash.rst
new file mode 100644 (file)
index 0000000..4240440
--- /dev/null
@@ -0,0 +1,34 @@
+.. include:: ../../Includes.txt
+
+=======================================================
+Important: #78336 - Generate preview links with a chash
+=======================================================
+
+See :issue:`78336`
+
+Description
+===========
+
+The preview link configuration has been extended to be able to generate links with a cHash.
+
+Provide the setting `useCacheHash = 1` to add a cHash. This is essential for records displayed
+using Extbase which enforces cHash usage.
+
+.. code-block:: typoscript
+
+       TCEMAIN.preview {
+               <table name> {
+                       previewPageId = 123
+                       useCacheHash = 1
+                       fieldToParameterMap {
+                               uid = tx_myext_pi1[showUid]
+                       }
+                       additionalGetParameters {
+                               tx_myext_pi1[special] = HELLO
+                       }
+               }
+       }
+
+If `useCacheHash = 1` is not set, the `no_cache` parameter will be added just like before.
+
+.. index:: Backend, Frontend, TSConfig