FIX Recipient email content previews now when when userforms is used in a trait context

This commit is contained in:
Robbie Averill 2018-09-07 10:45:11 +02:00
parent 9b48b4f954
commit c88d6b1566

View File

@ -234,12 +234,17 @@ class EmailRecipient extends DataObject
->getRequest() ->getRequest()
->setSession(Controller::curr()->getRequest()->getSession()); ->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( $preview = sprintf(
'<p><a href="%s" target="_blank" class="btn btn-outline-secondary">%s</a></p><em>%s</em>', '<p><a href="%s" target="_blank" class="btn btn-outline-secondary">%s</a></p><em>%s</em>',
Controller::join_links( $previewUrl,
$pageEditController->getEditForm()->FormAction(),
"field/EmailRecipients/item/{$this->ID}/preview"
),
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.PREVIEW_EMAIL', 'Preview email'), _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.PREVIEW_EMAIL', 'Preview email'),
_t( _t(
'SilverStripe\\UserForms\\Model\\UserDefinedForm.PREVIEW_EMAIL_DESCRIPTION', 'SilverStripe\\UserForms\\Model\\UserDefinedForm.PREVIEW_EMAIL_DESCRIPTION',