mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
FIX Preview email link now handles cases where it's loaded in the browser, requested via AJAX and used in a trait or a page context
This commit is contained in:
parent
d141c83e0a
commit
483fbc8499
@ -229,16 +229,21 @@ class EmailRecipient extends DataObject
|
||||
|
||||
// Only show the preview link if the recipient has been saved.
|
||||
if (!empty($this->EmailTemplate)) {
|
||||
$pageEditController = singleton(CMSPageEditController::class);
|
||||
$pageEditController
|
||||
->getRequest()
|
||||
->setSession(Controller::curr()->getRequest()->getSession());
|
||||
$request = Controller::curr()->getRequest();
|
||||
|
||||
$pageEditController = singleton(CMSPageEditController::class);
|
||||
$pageEditController->getRequest()->setSession($request->getSession());
|
||||
|
||||
$currentUrl = $request->getURL();
|
||||
// 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);
|
||||
// it won't. Strip that off in case. It may also have "ItemEditForm" on the end instead if this is
|
||||
// an AJAX request, e.g. saving a GridFieldDetailForm
|
||||
$remove = ['/edit', '/ItemEditForm'];
|
||||
foreach ($remove as $badSuffix) {
|
||||
$badSuffixLength = strlen($badSuffix);
|
||||
if (substr($currentUrl, -$badSuffixLength) === $badSuffix) {
|
||||
$currentUrl = substr($currentUrl, 0, -$badSuffixLength);
|
||||
}
|
||||
}
|
||||
$previewUrl = Controller::join_links($currentUrl, 'preview');
|
||||
|
||||
|
@ -29,7 +29,7 @@ class EmailRecipientTest extends SapphireTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException SilverStripe\ORM\ValidationException
|
||||
* @expectedException \SilverStripe\ORM\ValidationException
|
||||
* @expectedExceptionMessage "Send email to" address or field is required
|
||||
*/
|
||||
public function testEmptyRecipientFailsValidation()
|
||||
|
Loading…
Reference in New Issue
Block a user