Permalink
Browse files

ENHANCEMENT Per-instance customisation of GridFieldDetailForm_ItemReq…

…uest
  • Loading branch information...
1 parent ffe698c commit fed2785173833f20fbe1140eacf4d08ebf674ed4 @chillu chillu committed Apr 30, 2012
Showing with 42 additions and 5 deletions.
  1. +32 −5 forms/gridfield/GridFieldDetailForm.php
  2. +10 −0 tests/forms/gridfield/GridFieldDetailFormTest.php
@@ -28,6 +28,16 @@ class GridFieldDetailForm implements GridField_URLHandler {
*/
protected $validator;
+ /**
+ * @var String
+ */
+ protected $itemRequestClass;
+
+ /**
+ * @var function With two parameters: $form and $component
+ */
+ protected $itemEditFormCallback;
+
function getURLHandlers($gridField) {
return array(
'item/$ID' => 'handleItem',
@@ -64,11 +74,7 @@ public function handleItem($gridField, $request) {
$record = Object::create($gridField->getModelClass());
}
- if(ClassInfo::exists(get_class($this) . "_ItemRequest")) {
- $class = get_class($this) . "_ItemRequest";
- } else {
- $class = 'GridFieldDetailForm_ItemRequest';
- }
+ $class = $this->getItemRequestClass();
$handler = Object::create($class, $gridField, $this, $record, $controller, $this->name);
$handler->setTemplate($this->template);
@@ -120,6 +126,27 @@ public function setValidator(Validator $validator) {
public function getValidator() {
return $this->validator;
}
+
+ /**
+ * @param String
+ */
+ public function setItemRequestClass($class) {
+ $this->itemRequestClass = $class;
+ return $this;
+ }
+
+ /**
+ * @return String
+ */
+ public function getItemRequestClass() {
+ if($this->itemRequestClass) {
+ return $this->itemRequestClass;
+ } else if(ClassInfo::exists(get_class($this) . "_ItemRequest")) {
+ return get_class($this) . "_ItemRequest";
+ } else {
+ return 'GridFieldItemRequest_ItemRequest';
+ }
+ }
}
class GridFieldDetailForm_ItemRequest extends RequestHandler {
@@ -126,6 +126,13 @@ function testNestedEditForm() {
// Fourth level form would be a Category detail view
}
+
+ function testCustomItemRequestClass() {
+ $component = new GridFieldDetailForm();
+ $this->assertEquals('GridFieldDetailForm_ItemRequest', $component->getItemRequestClass());
+ $component->setItemRequestClass('GridFieldDetailFormTest_ItemRequest');
+ $this->assertEquals('GridFieldDetailFormTest_ItemRequest', $component->getItemRequestClass());
+ }
}
class GridFieldDetailFormTest_Person extends DataObject implements TestOnly {
@@ -230,3 +237,6 @@ function Form() {
return new Form($this, 'Form', new FieldList($field), new FieldList());
}
}
+
+class GridFieldDetailFormTest_ItemRequest extends GridFieldDetailForm_ItemRequest implements TestOnly {
+}

0 comments on commit fed2785

Please sign in to comment.