mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
API CHANGE: Allowing ModelAdmin::$managed_models to contain additional options in their array values, e.g. a custom "title" (Improved #4036, see r76999)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@77096 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
8625e3bce3
commit
80d79e63b8
@ -35,6 +35,21 @@ abstract class ModelAdmin extends LeftAndMain {
|
|||||||
/**
|
/**
|
||||||
* List of all managed {@link DataObject}s in this interface.
|
* List of all managed {@link DataObject}s in this interface.
|
||||||
*
|
*
|
||||||
|
* Simple notation with class names only:
|
||||||
|
* <code>
|
||||||
|
* array('MyObjectClass','MyOtherObjectClass')
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* Extended notation with options (e.g. custom titles):
|
||||||
|
* <code>
|
||||||
|
* array(
|
||||||
|
* 'MyObjectClass' => array('title' => "Custom title")
|
||||||
|
* )
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* Available options:
|
||||||
|
* - 'title': Set custom titles for the tabs or dropdown names
|
||||||
|
*
|
||||||
* @var array|string
|
* @var array|string
|
||||||
*/
|
*/
|
||||||
public static $managed_models = null;
|
public static $managed_models = null;
|
||||||
@ -155,9 +170,10 @@ abstract class ModelAdmin extends LeftAndMain {
|
|||||||
*/
|
*/
|
||||||
function defineMethods() {
|
function defineMethods() {
|
||||||
parent::defineMethods();
|
parent::defineMethods();
|
||||||
foreach($this->getManagedModels() as $ClassName) {
|
foreach($this->getManagedModels() as $class => $options) {
|
||||||
$this->addWrapperMethod($ClassName, 'bindModelController');
|
if(is_numeric($class)) $class = $options;
|
||||||
self::$allowed_actions[] = $ClassName;
|
$this->addWrapperMethod($class, 'bindModelController');
|
||||||
|
self::$allowed_actions[] = $class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,9 +207,10 @@ abstract class ModelAdmin extends LeftAndMain {
|
|||||||
$models = $this->getManagedModels();
|
$models = $this->getManagedModels();
|
||||||
$forms = new DataObjectSet();
|
$forms = new DataObjectSet();
|
||||||
|
|
||||||
foreach($models as $title => $class) {
|
foreach($models as $class => $options) {
|
||||||
|
if(is_numeric($class)) $class = $options;
|
||||||
$forms->push(new ArrayData(array (
|
$forms->push(new ArrayData(array (
|
||||||
'Title' => (is_string($title) ? $title : singleton($class)->singular_name()),
|
'Title' => (is_array($options) && isset($options['title'])) ? $options['title'] : singleton($class)->singular_name(),
|
||||||
'ClassName' => $class,
|
'ClassName' => $class,
|
||||||
'Content' => $this->$class()->getModelSidebar()
|
'Content' => $this->$class()->getModelSidebar()
|
||||||
)));
|
)));
|
||||||
@ -236,7 +253,10 @@ abstract class ModelAdmin extends LeftAndMain {
|
|||||||
// fallback to all defined models if not explicitly defined
|
// fallback to all defined models if not explicitly defined
|
||||||
if(is_null($importers)) {
|
if(is_null($importers)) {
|
||||||
$models = $this->getManagedModels();
|
$models = $this->getManagedModels();
|
||||||
foreach($models as $modelName) $importers[$modelName] = 'CsvBulkLoader';
|
foreach($models as $modelName => $options) {
|
||||||
|
if(is_numeric($modelName)) $modelName = $options;
|
||||||
|
$importers[$modelName] = 'CsvBulkLoader';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $importers;
|
return $importers;
|
||||||
|
Loading…
Reference in New Issue
Block a user