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() {
$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);

View File

@ -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);

View File

@ -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',

View File

@ -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);