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.
|
// Only show the preview link if the recipient has been saved.
|
||||||
if (!empty($this->EmailTemplate)) {
|
if (!empty($this->EmailTemplate)) {
|
||||||
$pageEditController = singleton(CMSPageEditController::class);
|
$request = Controller::curr()->getRequest();
|
||||||
$pageEditController
|
|
||||||
->getRequest()
|
|
||||||
->setSession(Controller::curr()->getRequest()->getSession());
|
|
||||||
|
|
||||||
|
$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
|
// 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.
|
// it won't. Strip that off in case. It may also have "ItemEditForm" on the end instead if this is
|
||||||
$currentUrl = Controller::curr()->getRequest()->getURL();
|
// an AJAX request, e.g. saving a GridFieldDetailForm
|
||||||
if (substr($currentUrl, -5) === '/edit') {
|
$remove = ['/edit', '/ItemEditForm'];
|
||||||
$currentUrl = substr($currentUrl, 0, strlen($currentUrl) - 5);
|
foreach ($remove as $badSuffix) {
|
||||||
|
$badSuffixLength = strlen($badSuffix);
|
||||||
|
if (substr($currentUrl, -$badSuffixLength) === $badSuffix) {
|
||||||
|
$currentUrl = substr($currentUrl, 0, -$badSuffixLength);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$previewUrl = Controller::join_links($currentUrl, 'preview');
|
$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
|
* @expectedExceptionMessage "Send email to" address or field is required
|
||||||
*/
|
*/
|
||||||
public function testEmptyRecipientFailsValidation()
|
public function testEmptyRecipientFailsValidation()
|
||||||
|
Loading…
Reference in New Issue
Block a user