Permalink
Browse files

BUGFIX Ensure that CMSMain rule doesn't override the CMSPagesController

rule in AdminRootController::add_rule_for_controller()
  • Loading branch information...
1 parent d522b81 commit ae1a106600d649defed3fb2811eff24e1b741dcb @halkyon halkyon committed May 22, 2012
Showing with 5 additions and 6 deletions.
  1. +5 −6 admin/code/AdminRootController.php
@@ -37,7 +37,7 @@ public static function rules() {
// Build an array of class => url_priority k/v pairs
$classes = array();
foreach (CMSMenu::get_cms_classes() as $class) {
- $classes[$class] = Config::inst()->get($class, 'url_priority', Config::FIRST_SET);
+ $classes[$class] = Config::inst()->get($class, 'url_priority', Config::FIRST_SET);
}
// Sort them so highest priority item is first
@@ -46,7 +46,6 @@ public static function rules() {
// Map over the array calling add_rule_for_controller on each
array_map(array(__CLASS__, 'add_rule_for_controller'), array_keys($classes));
}
-
return self::$_rules;
}
@@ -57,12 +56,13 @@ protected static function add_rule_for_controller($controllerClass) {
$urlSegment = Config::inst()->get($controllerClass, 'url_segment', Config::FIRST_SET);
$urlRule = Config::inst()->get($controllerClass, 'url_rule', Config::FIRST_SET);
- if($urlSegment || $controllerClass == 'CMSMain') {
+ if($urlSegment) {
// Make director rule
if($urlRule[0] == '/') $urlRule = substr($urlRule,1);
$rule = $urlSegment . '//' . $urlRule;
- self::$_rules[$rule] = $controllerClass;
+ // ensure that the first call to add_rule_for_controller for a rule takes precedence
+ if(!isset(self::$_rules[$rule])) self::$_rules[$rule] = $controllerClass;
}
}
@@ -80,7 +80,6 @@ function handleRequest(SS_HTTPRequest $request, DataModel $model) {
// Otherwise
else {
$rules = self::rules();
-
foreach($rules as $pattern => $controller) {
if(($arguments = $request->match($pattern, true)) !== false) {
$controllerObj = Injector::inst()->create($controller);
@@ -91,4 +90,4 @@ function handleRequest(SS_HTTPRequest $request, DataModel $model) {
}
}
}
-}
+}

0 comments on commit ae1a106

Please sign in to comment.