From ba0d1c60cb5a27b318eb8c460541c65c30d5e003 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 27 Feb 2012 17:41:01 +0100 Subject: [PATCH] MINOR Don't require controller on instanciation of GridFieldPopupForms, as it can't be reliably determined e.g. during a getCMSFields() call. Should use existing FormField/Form API to retrieve controller when its required. MINOR Renamed GridFieldPopupForms->popupFormName to $name to make it clearer that its the component name (which is optional now). --- admin/code/SecurityAdmin.php | 2 +- filesystem/Folder.php | 2 +- forms/gridfield/GridFieldPopupForms.php | 44 ++++++++++++++++--------- security/Group.php | 2 +- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/admin/code/SecurityAdmin.php b/admin/code/SecurityAdmin.php index b7332a8bc..678c08993 100755 --- a/admin/code/SecurityAdmin.php +++ b/admin/code/SecurityAdmin.php @@ -107,7 +107,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider { */ function RootForm() { $config = new GridFieldConfig_Base(25); - $config->addComponent(new GridFieldPopupForms($this, 'RootForm')); + $config->addComponent(new GridFieldPopupForms()); $config->addComponent(new GridFieldExporter()); $memberList = new GridField('Members', 'All members', DataList::create('Member'), $config); diff --git a/filesystem/Folder.php b/filesystem/Folder.php index 87a86aa64..dccf2844b 100644 --- a/filesystem/Folder.php +++ b/filesystem/Folder.php @@ -405,7 +405,7 @@ class Folder extends File { $config->addComponent(new GridFieldPaginator(10)); $config->addComponent(new GridFieldAction_Delete()); $config->addComponent(new GridFieldAction_Edit()); - $config->addComponent($gridFieldForm = new GridFieldPopupForms(Controller::curr(), 'EditForm')); + $config->addComponent($gridFieldForm = new GridFieldPopupForms(); $gridFieldForm->setTemplate('CMSGridFieldPopupForms'); $files = DataList::create('File')->filter('ParentID', $this->ID)->exclude('ClassName', 'Folder'); $gridField = new GridField('File','Files', $files, $config); diff --git a/forms/gridfield/GridFieldPopupForms.php b/forms/gridfield/GridFieldPopupForms.php index 82e0d0b85..2a38fa96e 100755 --- a/forms/gridfield/GridFieldPopupForms.php +++ b/forms/gridfield/GridFieldPopupForms.php @@ -9,22 +9,18 @@ */ class GridFieldPopupForms implements GridField_URLHandler { + + /** * @var String */ protected $template = 'GridFieldItemEditView'; - /** - * - * @var Controller - */ - protected $popupController; - /** * * @var string */ - protected $popupFormName; + protected $name; function getURLHandlers($gridField) { return array( @@ -41,12 +37,10 @@ class GridFieldPopupForms implements GridField_URLHandler { * The arguments are experimental API's to support partial content to be passed back to whatever * controller who wants to display the getCMSFields * - * @param Controller $popupController The controller object that will be used to render the pop-up forms - * @param string $popupFormName The name of the edit form to place into the pop-up form + * @param string $name The name of the edit form to place into the pop-up form */ - public function __construct($popupController, $popupFormName) { - $this->popupController = $popupController; - $this->popupFormName = $popupFormName; + public function __construct($name = 'DetailForm') { + $this->name = $name; } /** @@ -56,13 +50,18 @@ class GridFieldPopupForms implements GridField_URLHandler { * @return GridFieldPopupForm_ItemRequest */ public function handleItem($gridField, $request) { + $controller = $gridField->getForm()->Controller(); if(is_numeric($request->param('ID'))) { $record = $gridField->getList()->byId($request->param("ID")); } else { $record = Object::create($gridField->getModelClass()); } - $handler = new GridFieldPopupForm_ItemRequest($gridField, $this, $record, $this->popupController, $this->popupFormName); + if(!$class = ClassInfo::exists(get_class($this) . "_ItemRequest")) { + $class = 'GridFieldPopupForm_ItemRequest'; + } + + $handler = Object::create($class, $gridField, $this, $record, $controller, $this->name); $handler->setTemplate($this->template); return $handler->handleRequest($request, $gridField); @@ -81,6 +80,20 @@ class GridFieldPopupForms implements GridField_URLHandler { function getTemplate() { return $this->template; } + + /** + * @param String + */ + function setName($name) { + $this->name = $name; + } + + /** + * @return String + */ + function getName() { + return $this->name; + } } class GridFieldPopupForm_ItemRequest extends RequestHandler { @@ -150,8 +163,8 @@ class GridFieldPopupForm_ItemRequest extends RequestHandler { $controller = $this->popupController; $return = $this->customise(array( - 'Backlink' => $this->gridField->getForm()->Controller()->Link(), - 'ItemEditForm' => $this->ItemEditForm($this->gridField, $request), + 'Backlink' => $controller->Link(), + 'ItemEditForm' => $form, ))->renderWith($this->template); if($controller->isAjax()) { @@ -176,7 +189,6 @@ class GridFieldPopupForm_ItemRequest extends RequestHandler { * @return Form */ function ItemEditForm() { - $request = $this->popupController->getRequest(); $form = new Form( $this, 'ItemEditForm', diff --git a/security/Group.php b/security/Group.php index 10dfea0d5..b40e388af 100755 --- a/security/Group.php +++ b/security/Group.php @@ -63,7 +63,7 @@ class Group extends DataObject { Requirements::javascript(SAPPHIRE_DIR . '/javascript/PermissionCheckboxSetField.js'); $config = new GridFieldConfig_ManyManyEditor('FirstName', true, 20); - $config->addComponent(new GridFieldPopupForms(Controller::curr(), 'EditForm')); + $config->addComponent(new GridFieldPopupForms()); $config->addComponent(new GridFieldExporter()); $memberList = new GridField('Members','Members', $this->Members(), $config);