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', - 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',