From c88d6b1566659c0d5fac5ac408f05def0ecddee4 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 7 Sep 2018 10:45:11 +0200 Subject: [PATCH] FIX Recipient email content previews now when when userforms is used in a trait context --- code/Model/Recipient/EmailRecipient.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/code/Model/Recipient/EmailRecipient.php b/code/Model/Recipient/EmailRecipient.php index 4a3a546..0c686a4 100644 --- a/code/Model/Recipient/EmailRecipient.php +++ b/code/Model/Recipient/EmailRecipient.php @@ -234,12 +234,17 @@ class EmailRecipient extends DataObject ->getRequest() ->setSession(Controller::curr()->getRequest()->getSession()); + // If used in a regular page context, will have "/edit" on the end, if used in a trait context + // it won't. Strip that off in case. + $currentUrl = Controller::curr()->getRequest()->getURL(); + if (substr($currentUrl, -5) === '/edit') { + $currentUrl = substr($currentUrl, 0, strlen($currentUrl) - 5); + } + $previewUrl = Controller::join_links($currentUrl, 'preview'); + $preview = sprintf( '

%s

%s', - Controller::join_links( - $pageEditController->getEditForm()->FormAction(), - "field/EmailRecipients/item/{$this->ID}/preview" - ), + $previewUrl, _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.PREVIEW_EMAIL', 'Preview email'), _t( 'SilverStripe\\UserForms\\Model\\UserDefinedForm.PREVIEW_EMAIL_DESCRIPTION',