[BUGFIX] Make it possible to add cHash to preview links
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / EditDocumentController.php
index ece077c..ef05fc2 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;
 
 /**
@@ -828,9 +829,7 @@ class EditDocumentController extends AbstractModule
             }
         }
 
-        $linkParameters = [
-            'no_cache' => 1,
-        ];
+        $linkParameters = [];
 
         // language handling
         $languageField = isset($GLOBALS['TCA'][$table]['ctrl']['languageField'])
@@ -871,6 +870,16 @@ class EditDocumentController extends AbstractModule
             $linkParameters = array_replace($linkParameters, $additionalGetParameters);
         }
 
+        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);