Commit a97accab authored by Christian Kuhn's avatar Christian Kuhn

[BUGFIX] Working preview links in workspace mails

Fix a couple of issues with state change emails in

* We still can't deep link to the backend. The generated
  comparisonLink to the side-by-side preview module is a
  workspace backend functionality. The generated links
  don't work and show the login form. The fix is to
  generate "preview links" instead which call a frontend.
  We may be able to improve this later, when core v11
  allows deep linking.

* When changing the stage of a page delete placeholder
  - when a page is for deletion in live - preview link
  generation to these pages does not make sense, trying
  to generate such a link throws an exception "no
  connection to page tree", the ajax request fails and
  no mails are send. Fix is to catch the exception and
  leave out the link in the emails.

* Preview links did not carry the language id when
  sending notifications for state changes of non default
  language records. This is added to properly link to
  non-default language previews.

* A missing closing p-tag in the HTML mail.

* As a better default, preview links are now always added
  to the mails if possible. In rare cases where this is
  not wanted, the mail templates should be adapted.

Change-Id: I84f0e4e5131d52ecbc5e7424137ae7e2ebdb2031
Resolves: #91515
Resolves: #81708
Related: #90411
Releases: master, 10.4
Reviewed-on: default avatarTYPO3com <>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <>
Tested-by: Benni Mack's avatarBenni Mack <>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <>
Reviewed-by: Benni Mack's avatarBenni Mack <>
parent b18c047b
......@@ -23,11 +23,6 @@ The following TSconfig options have been added:
.. code-block:: typoscript
# defines whether a preview link should be generated and populating
# the sys_preview database. A new variable {previewLink}
# is then available within the templated email
tx_workspaces.emails.stageChangeNotification.generatePreviewLink = 0
# path where to look for templates / layouts / partials
tx_workspaces.emails.layoutRootPaths.100 = EXT:myproject/...
tx_workspaces.emails.partialRootPaths.100 = EXT:myproject/...
......@@ -23,6 +23,7 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Mail\FluidEmail;
use TYPO3\CMS\Core\Mail\Mailer;
use TYPO3\CMS\Core\Routing\UnableToLinkToPageException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\TemplatePaths;
use TYPO3\CMS\Workspaces\Preview\PreviewUriBuilder;
......@@ -77,9 +78,18 @@ class StageChangeNotification
$elementRecord = (array)BackendUtility::getRecord($elementTable, $elementUid);
$recordTitle = BackendUtility::getRecordTitle($elementTable, $elementRecord);
$pageUid = $this->findFirstPageId($elementTable, $elementUid, $elementRecord);
$emailConfig = BackendUtility::getPagesTSconfig($pageUid)['tx_workspaces.']['emails.'] ?? [];
$emailConfig = GeneralUtility::removeDotsFromTS($emailConfig);
$previewLink = '';
try {
$languageId = $elementRecord[$GLOBALS['TCA'][$elementTable]['ctrl']['languageField'] ?? ''] ?? 0;
$previewLink = $this->previewUriBuilder->buildUriForPage($pageUid, $languageId);
} catch (UnableToLinkToPageException $e) {
// Generating a preview for a page that is is a delete placeholder
// in workspaces fails. No preview link in this case.
$viewPlaceholders = [
'pageId' => $pageUid,
'workspace' => $workspaceRecord,
......@@ -89,13 +99,9 @@ class StageChangeNotification
'recordTitle' => $recordTitle,
'affectedElements' => $affectedElements,
'nextStage' => $this->stagesService->getStageTitle($stageId),
'comparisonView' => (string)$this->previewUriBuilder->buildUriForWorkspaceSplitPreview($pageUid)
'previewLink' => $previewLink
if ($emailConfig['stageChangeNotification']['generatePreviewLink']) {
$viewPlaceholders['previewLink'] = $this->previewUriBuilder->buildUriForPage($pageUid, 0);
$sentEmails = [];
foreach ($recipients as $recipientData) {
// don't send an email twice
......@@ -15,12 +15,9 @@
The first entry was "{recordTitle}" at location <code>"{rootLine}"</code> in the page tree.
See the changes in the <a href="{comparisonView}">comparison view</a>.
<f:if condition="{previewLink}">
<p><a href="{previewLink}" rel="noopener">See a preview of the changed page.</a>
<p><a href="{previewLink}" rel="noopener">See a preview of the changed page.</a></p>
......@@ -10,7 +10,6 @@ At the TYPO3 site "{typo3.sitename}" in workspace "{workspace.title}" ({workspac
The first entry was "{recordTitle}" at location "{rootLine}" in the page tree.
See the changes in the comparison view {comparisonView}.
<f:if condition="{previewLink}">
See a preview of the changed page here {previewLink}
......@@ -4,7 +4,6 @@ defined('TYPO3') or die();
// add default notification options to every page
tx_workspaces.emails.stageChangeNotification.generatePreviewLink = 0
tx_workspaces.emails.layoutRootPaths.90 = EXT:workspaces/Resources/Private/Layouts/
tx_workspaces.emails.partialRootPaths.90 = EXT:workspaces/Resources/Private/Partials/
tx_workspaces.emails.templateRootPaths.90 = EXT:workspaces/Resources/Private/Templates/Email/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment