mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Per-instance customisation of GridFieldDetailForm_ItemRequest
This commit is contained in:
parent
ffe698ca1e
commit
fed2785173
@ -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 @@ class GridFieldDetailForm implements GridField_URLHandler {
|
||||
$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 @@ class GridFieldDetailForm implements GridField_URLHandler {
|
||||
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 @@ class GridFieldDetailFormTest extends FunctionalTest {
|
||||
|
||||
// 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 @@ class GridFieldDetailFormTest_GroupController extends Controller implements Test
|
||||
return new Form($this, 'Form', new FieldList($field), new FieldList());
|
||||
}
|
||||
}
|
||||
|
||||
class GridFieldDetailFormTest_ItemRequest extends GridFieldDetailForm_ItemRequest implements TestOnly {
|
||||
}
|
Loading…
Reference in New Issue
Block a user