Permalink
Browse files

BUGFIX Return consistent data from ModelAdmin->getManagedModels(), fi…

…xing custom 'title' settings in $managed_models (fixes #7243)
  • Loading branch information...
1 parent e29bb3c commit c7323545b64f5b3f4a1ff5c2028d9ec3cc2efaad @chillu chillu committed May 2, 2012
Showing with 13 additions and 12 deletions.
  1. +13 −12 admin/code/ModelAdmin.php
View
@@ -103,10 +103,10 @@ public function init() {
parent::init();
$models = $this->getManagedModels();
- $this->modelClass = (isset($this->urlParams['ModelClass'])) ? $this->urlParams['ModelClass'] : $models[0];
+ $this->modelClass = (isset($this->urlParams['ModelClass'])) ? $this->urlParams['ModelClass'] : key($models);
// security check for valid models
- if(!in_array($this->modelClass, $models)) {
+ if(!array_key_exists($this->modelClass, $models)) {
user_error('ModelAdmin::init(): Invalid Model class', E_USER_ERROR);
}
@@ -226,9 +226,8 @@ protected function getManagedModelTabs() {
$forms = new ArrayList();
foreach($models as $class => $options) {
- if(is_numeric($class)) $class = $options;
$forms->push(new ArrayData(array (
- 'Title' => (is_array($options) && isset($options['title'])) ? $options['title'] : singleton($class)->i18n_singular_name(),
+ 'Title' => $options['title'],
'ClassName' => $class,
'Link' => $this->Link($class),
'LinkOrCurrent' => ($class == $this->modelClass) ? 'current' : 'link'
@@ -239,7 +238,7 @@ protected function getManagedModelTabs() {
}
/**
- * @return array
+ * @return array Map of class name to an array of 'title' (see {@link $managed_models})
*/
function getManagedModels() {
$models = $this->stat('managed_models');
@@ -254,6 +253,14 @@ function getManagedModels() {
E_USER_ERROR
);
}
+
+ // Normalize models to have their model class in array key
+ foreach($models as $k => $v) {
+ if(is_numeric($k)) {
+ $models[$v] = array('title' => singleton($v)->i18n_singular_name());
+ unset($models[$k]);
+ }
+ }
return $models;
}
@@ -273,7 +280,6 @@ function getModelImporters() {
if(is_null($importerClasses)) {
$models = $this->getManagedModels();
foreach($models as $modelName => $options) {
- if(is_numeric($modelName)) $modelName = $options;
$importerClasses[$modelName] = 'CsvBulkLoader';
}
}
@@ -407,12 +413,7 @@ public function Breadcrumbs($unlinked = false) {
// Show the class name rather than ModelAdmin title as root node
$models = $this->getManagedModels();
- $modelSpec = ArrayLib::is_associative($models) ? $models[$this->modelClass] : null;
- if(is_array($modelSpec) && isset($modelSpec['title'])) {
- $items[0]->Title = $modelSpec['title'];
- } else {
- $items[0]->Title = singleton($this->modelClass)->i18n_singular_name();
- }
+ $items[0]->Title = $models[$this->modelClass]['title'];
$items[0]->Link = $this->Link($this->modelClass);
return $items;

0 comments on commit c732354

Please sign in to comment.