Merge pull request #5834 from tractorcow/pulls/4.0/fix-admin

BUG Fix regressions in custom admin url from #3274
This commit is contained in:
Daniel Hensby 2016-07-22 09:31:03 +01:00 committed by GitHub
commit c130e5550d
2 changed files with 13 additions and 12 deletions

View File

@ -8,29 +8,30 @@ use SilverStripe\ORM\DataModel;
*/ */
class AdminRootController extends Controller implements TemplateGlobalProvider { class AdminRootController extends Controller implements TemplateGlobalProvider {
/**
* Fallback admin URL in case this cannot be infered from Director.rules
*
* @var string
* @config
*/
private static $url_base = 'admin';
/** /**
* Convenience function to return the admin route config. * Convenience function to return the admin route config.
* Looks for the {@link Director::$rules} for the current admin Controller. * Looks for the {@link Director::$rules} for the current admin Controller.
*
* @return string
*/ */
public static function get_admin_route() { public static function get_admin_route() {
if (Controller::has_curr()) {
$routeParams = Controller::curr()->getRequest()->routeParams();
$adminControllerClass = isset($routeParams['Controller']) ? $routeParams['Controller'] : get_called_class();
}
else {
$adminControllerClass = get_called_class();
}
$rules = Config::inst()->get('Director', 'rules'); $rules = Config::inst()->get('Director', 'rules');
$adminRoute = array_search($adminControllerClass, $rules); $adminRoute = array_search(__CLASS__, $rules);
return $adminRoute ? $adminRoute : ''; return $adminRoute ?: static::config()->url_base;
} }
/** /**
* Returns the root admin URL for the site with trailing slash * Returns the root admin URL for the site with trailing slash
* *
* @return string * @return string
* @uses get_admin_route()
*/ */
public static function admin_url() { public static function admin_url() {
return self::get_admin_route() . '/'; return self::get_admin_route() . '/';

View File

@ -3,7 +3,7 @@
<% with $CurrentMember %> <% with $CurrentMember %>
<span> <span>
<%t LeftAndMain_Menu_ss.Hello 'Hi' %> <%t LeftAndMain_Menu_ss.Hello 'Hi' %>
<a href="{$AbsoluteBaseURL}{$AdminURL}admin/myprofile" class="profile-link"> <a href="{$AdminURL}myprofile" class="profile-link">
<% if $FirstName && $Surname %>$FirstName $Surname<% else_if $FirstName %>$FirstName<% else %>$Email<% end_if %> <% if $FirstName && $Surname %>$FirstName $Surname<% else_if $FirstName %>$FirstName<% else %>$Email<% end_if %>
</a> </a>
</span> </span>