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).
This commit is contained in:
Ingo Schommer 2012-02-27 17:41:01 +01:00
parent 3936909980
commit ba0d1c60cb
4 changed files with 31 additions and 19 deletions

View File

@ -107,7 +107,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
*/ */
function RootForm() { function RootForm() {
$config = new GridFieldConfig_Base(25); $config = new GridFieldConfig_Base(25);
$config->addComponent(new GridFieldPopupForms($this, 'RootForm')); $config->addComponent(new GridFieldPopupForms());
$config->addComponent(new GridFieldExporter()); $config->addComponent(new GridFieldExporter());
$memberList = new GridField('Members', 'All members', DataList::create('Member'), $config); $memberList = new GridField('Members', 'All members', DataList::create('Member'), $config);

View File

@ -405,7 +405,7 @@ class Folder extends File {
$config->addComponent(new GridFieldPaginator(10)); $config->addComponent(new GridFieldPaginator(10));
$config->addComponent(new GridFieldAction_Delete()); $config->addComponent(new GridFieldAction_Delete());
$config->addComponent(new GridFieldAction_Edit()); $config->addComponent(new GridFieldAction_Edit());
$config->addComponent($gridFieldForm = new GridFieldPopupForms(Controller::curr(), 'EditForm')); $config->addComponent($gridFieldForm = new GridFieldPopupForms();
$gridFieldForm->setTemplate('CMSGridFieldPopupForms'); $gridFieldForm->setTemplate('CMSGridFieldPopupForms');
$files = DataList::create('File')->filter('ParentID', $this->ID)->exclude('ClassName', 'Folder'); $files = DataList::create('File')->filter('ParentID', $this->ID)->exclude('ClassName', 'Folder');
$gridField = new GridField('File','Files', $files, $config); $gridField = new GridField('File','Files', $files, $config);

View File

@ -9,22 +9,18 @@
*/ */
class GridFieldPopupForms implements GridField_URLHandler { class GridFieldPopupForms implements GridField_URLHandler {
/** /**
* @var String * @var String
*/ */
protected $template = 'GridFieldItemEditView'; protected $template = 'GridFieldItemEditView';
/**
*
* @var Controller
*/
protected $popupController;
/** /**
* *
* @var string * @var string
*/ */
protected $popupFormName; protected $name;
function getURLHandlers($gridField) { function getURLHandlers($gridField) {
return array( 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 * The arguments are experimental API's to support partial content to be passed back to whatever
* controller who wants to display the getCMSFields * 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 $name The name of the edit form to place into the pop-up form
* @param string $popupFormName The name of the edit form to place into the pop-up form
*/ */
public function __construct($popupController, $popupFormName) { public function __construct($name = 'DetailForm') {
$this->popupController = $popupController; $this->name = $name;
$this->popupFormName = $popupFormName;
} }
/** /**
@ -56,13 +50,18 @@ class GridFieldPopupForms implements GridField_URLHandler {
* @return GridFieldPopupForm_ItemRequest * @return GridFieldPopupForm_ItemRequest
*/ */
public function handleItem($gridField, $request) { public function handleItem($gridField, $request) {
$controller = $gridField->getForm()->Controller();
if(is_numeric($request->param('ID'))) { if(is_numeric($request->param('ID'))) {
$record = $gridField->getList()->byId($request->param("ID")); $record = $gridField->getList()->byId($request->param("ID"));
} else { } else {
$record = Object::create($gridField->getModelClass()); $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); $handler->setTemplate($this->template);
return $handler->handleRequest($request, $gridField); return $handler->handleRequest($request, $gridField);
@ -81,6 +80,20 @@ class GridFieldPopupForms implements GridField_URLHandler {
function getTemplate() { function getTemplate() {
return $this->template; return $this->template;
} }
/**
* @param String
*/
function setName($name) {
$this->name = $name;
}
/**
* @return String
*/
function getName() {
return $this->name;
}
} }
class GridFieldPopupForm_ItemRequest extends RequestHandler { class GridFieldPopupForm_ItemRequest extends RequestHandler {
@ -150,8 +163,8 @@ class GridFieldPopupForm_ItemRequest extends RequestHandler {
$controller = $this->popupController; $controller = $this->popupController;
$return = $this->customise(array( $return = $this->customise(array(
'Backlink' => $this->gridField->getForm()->Controller()->Link(), 'Backlink' => $controller->Link(),
'ItemEditForm' => $this->ItemEditForm($this->gridField, $request), 'ItemEditForm' => $form,
))->renderWith($this->template); ))->renderWith($this->template);
if($controller->isAjax()) { if($controller->isAjax()) {
@ -176,7 +189,6 @@ class GridFieldPopupForm_ItemRequest extends RequestHandler {
* @return Form * @return Form
*/ */
function ItemEditForm() { function ItemEditForm() {
$request = $this->popupController->getRequest();
$form = new Form( $form = new Form(
$this, $this,
'ItemEditForm', 'ItemEditForm',

View File

@ -63,7 +63,7 @@ class Group extends DataObject {
Requirements::javascript(SAPPHIRE_DIR . '/javascript/PermissionCheckboxSetField.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/PermissionCheckboxSetField.js');
$config = new GridFieldConfig_ManyManyEditor('FirstName', true, 20); $config = new GridFieldConfig_ManyManyEditor('FirstName', true, 20);
$config->addComponent(new GridFieldPopupForms(Controller::curr(), 'EditForm')); $config->addComponent(new GridFieldPopupForms());
$config->addComponent(new GridFieldExporter()); $config->addComponent(new GridFieldExporter());
$memberList = new GridField('Members','Members', $this->Members(), $config); $memberList = new GridField('Members','Members', $this->Members(), $config);