Add formGetRedirectUrl method. (#4954)

Fixes #4946. Documented in https://github.com/octobercms/docs/pull/432
This commit is contained in:
Flynsarmy 2020-03-22 16:32:27 +10:00 committed by GitHub
parent 09b7e1b2fd
commit 39980d8346
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 4 deletions

View File

@ -474,7 +474,7 @@ class FormController extends ControllerBehavior
}
if (post('redirect', true)) {
$redirectUrl = $this->getRedirectUrl($context);
$redirectUrl = $this->controller->formGetRedirectUrl($context, $model);
}
if ($model && $redirectUrl) {
@ -493,13 +493,15 @@ class FormController extends ControllerBehavior
}
/**
* Internal method that returns a redirect URL from the config based on
* supplied context. Otherwise the default redirect is used.
* Returns a redirect URL from the config based on supplied context.
* Otherwise the default redirect is used. Relative URLs are treated as
* backend URLs.
*
* @param string $context Redirect context, eg: create, update, delete.
* @param Model $model The active model.
* @return string
*/
protected function getRedirectUrl($context = null)
public function formGetRedirectUrl($context = null, $model = null)
{
$redirectContext = explode('-', $context, 2)[0];
$redirectSource = ends_with($context, '-close') ? 'redirectClose' : 'redirect';