From 4adb585e80f055da7e0d290362ae2819ed5e4b33 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Sat, 16 May 2009 05:58:54 +0000 Subject: [PATCH] ENHANCEMENT ajshort: Add the ability to overload getModelForms() and add new custom model sidebars. API CHANGE: Move the generation of the content for the create / search / import model sidebar from ModelAdmin into the collection controller. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@76997 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/ModelAdmin.php | 33 ++++++++++-------- templates/Includes/ModelAdmin_left.ss | 50 ++++++++++----------------- templates/ModelSidebar.ss | 12 +++++++ 3 files changed, 50 insertions(+), 45 deletions(-) create mode 100644 templates/ModelSidebar.ss diff --git a/code/ModelAdmin.php b/code/ModelAdmin.php index 19595fe2..fdeb0c94 100644 --- a/code/ModelAdmin.php +++ b/code/ModelAdmin.php @@ -188,18 +188,14 @@ abstract class ModelAdmin extends LeftAndMain { * @return DataObjectSet of forms */ protected function getModelForms() { - $modelClasses = $this->getManagedModels(); + $models = $this->getManagedModels(); + $forms = new DataObjectSet(); - $forms = new DataObjectSet(); - foreach($modelClasses as $modelClass) { - $this->$modelClass()->SearchForm(); - - $forms->push(new ArrayData(array( - 'SearchForm' => $this->$modelClass()->SearchForm(), - 'CreateForm' => $this->$modelClass()->CreateForm(), - 'ImportForm' => $this->$modelClass()->ImportForm(), - 'Title' => singleton($modelClass)->singular_name(), - 'ClassName' => $modelClass, + foreach($models as $class) { + $forms->push(new ArrayData(array ( + 'Title' => singleton($class)->singular_name(), + 'ClassName' => $class, + 'Content' => $this->$class()->getModelSidebar() ))); } @@ -313,9 +309,18 @@ class ModelAdmin_CollectionController extends Controller { $class = $this->parentController->stat('record_controller_class'); return new $class($this, $request); } - - ///////////////////////////////////////////////////////////////////////////////////////////////////////// - + + // ----------------------------------------------------------------------------------------------------------------- + + /** + * Get a combination of the Search, Import and Create forms that can be inserted into a {@link ModelAdmin} sidebar. + * + * @return string + */ + public function getModelSidebar() { + return $this->renderWith('ModelSidebar'); + } + /** * Get a search form for a single {@link DataObject} subclass. * diff --git a/templates/Includes/ModelAdmin_left.ss b/templates/Includes/ModelAdmin_left.ss index a25b148f..83c4117c 100755 --- a/templates/Includes/ModelAdmin_left.ss +++ b/templates/Includes/ModelAdmin_left.ss @@ -1,43 +1,31 @@ <% require javascript(jsparty/tabstrip/tabstrip.js) %> <% require css(jsparty/tabstrip/tabstrip.css) %> +
-
- <% if SearchClassSelector = tabs %> -
    - <% control ModelForms %> -
  • $Title
  • - <% end_control %> -
+ <% if SearchClassSelector = tabs %> +
    + <% control ModelForms %> +
  • $Title
  • + <% end_control %> +
<% end_if %> <% if SearchClassSelector = dropdown %> -

- Search for: - -

- <% end_if %> +

+ Search for: + +

+ <% end_if %> <% control ModelForms %> -
- <% if CreateForm %> -

<% _t('ADDLISTING','Add') %>

- $CreateForm - <% end_if %> - -

<% _t('SEARCHLISTINGS','Search') %>

- $SearchForm - - <% if ImportForm %> -

<% _t('IMPORT_TAB_HEADER', 'Import') %>

- $ImportForm - <% end_if %> - -
+
+ $Content +
<% end_control %>
\ No newline at end of file diff --git a/templates/ModelSidebar.ss b/templates/ModelSidebar.ss new file mode 100644 index 00000000..04092995 --- /dev/null +++ b/templates/ModelSidebar.ss @@ -0,0 +1,12 @@ +<% if CreateForm %> +

<% _t('ADDLISTING','Add') %>

+ $CreateForm +<% end_if %> + +

<% _t('SEARCHLISTINGS','Search') %>

+$SearchForm + +<% if ImportForm %> +

<% _t('IMPORT_TAB_HEADER', 'Import') %>

+ $ImportForm +<% end_if %> \ No newline at end of file