Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirectBackURL could be explicitly changed by users #258

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions src/SleepingOwl/Admin/Form/FormDefault.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace SleepingOwl\Admin\Form;

use AdminTemplate;
use Config;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\View\View;
use Input;
Expand Down Expand Up @@ -215,6 +216,48 @@ public function validate($model)
return null;
}

/**
* Get redirect back URL
* @return array|string
* @throws ModelNotFoundException
*/
protected function obtainRedirectBack(){
$redirect_back = Input::input('_redirectBack',null);
if ($redirect_back != null) {
return $this->beSureIsAbsoluteURL($redirect_back);
} else {
return $this->display_url($this->class);
}

}

protected function beSureIsAbsoluteURL($url) {
if (starts_with($url,'http://') || starts_with($url,'https://')) {
return $url;
} else {
if (starts_with($url,'/')) {
return URL::to('/') . $url;
} else {
return URL::to('/') . '/'. $url;
}
}
}

/**
* Get display URL (list of item models)
* @param $model
* @return string
* @throws ModelNotFoundException
*/
protected function display_url($model) {
if (array_key_exists($model,Admin::modelAliases())) {
$alias = Admin::modelAliases()[$model];
return URL::to('/') . '/' . Config::get('admin.prefix') . '/' . $alias ;
} else {
throw new ModelNotFoundException;
}
}

/**
* @return View
*/
Expand All @@ -224,7 +267,7 @@ public function render()
'items' => $this->items(),
'instance' => $this->instance(),
'action' => $this->action,
'backUrl' => session('_redirectBack', URL::previous()),
'backUrl' => $this->obtainRedirectBack(),
];
return view(AdminTemplate::view('form.' . $this->view), $params);
}
Expand All @@ -237,4 +280,4 @@ function __toString()
return (string)$this->render();
}

}
}