mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT GridFieldDetailForm->setItemEditFormCallback()
This commit is contained in:
parent
fed2785173
commit
72eadef113
@ -147,6 +147,20 @@ class GridFieldDetailForm implements GridField_URLHandler {
|
|||||||
return 'GridFieldItemRequest_ItemRequest';
|
return 'GridFieldItemRequest_ItemRequest';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param function $cb Make changes on the edit form after constructing it.
|
||||||
|
*/
|
||||||
|
public function setItemEditFormCallback($cb) {
|
||||||
|
$this->itemEditFormCallback = $cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return function
|
||||||
|
*/
|
||||||
|
public function getItemEditFormCallback() {
|
||||||
|
return $this->itemEditFormCallback;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GridFieldDetailForm_ItemRequest extends RequestHandler {
|
class GridFieldDetailForm_ItemRequest extends RequestHandler {
|
||||||
@ -296,6 +310,10 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler {
|
|||||||
// e.g. page/edit/show/6/ vs. page/edit/EditForm/field/MyGridField/....
|
// e.g. page/edit/show/6/ vs. page/edit/EditForm/field/MyGridField/....
|
||||||
$form->Backlink = $toplevelController->Link();
|
$form->Backlink = $toplevelController->Link();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cb = $this->component->getItemEditFormCallback();
|
||||||
|
if($cb) $cb($form, $this);
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +133,25 @@ class GridFieldDetailFormTest extends FunctionalTest {
|
|||||||
$component->setItemRequestClass('GridFieldDetailFormTest_ItemRequest');
|
$component->setItemRequestClass('GridFieldDetailFormTest_ItemRequest');
|
||||||
$this->assertEquals('GridFieldDetailFormTest_ItemRequest', $component->getItemRequestClass());
|
$this->assertEquals('GridFieldDetailFormTest_ItemRequest', $component->getItemRequestClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItemEditFormCallback() {
|
||||||
|
$category = new GridFieldDetailFormTest_Category();
|
||||||
|
$component = new GridFieldDetailForm();
|
||||||
|
$component->setItemEditFormCallback(function($form, $component) {
|
||||||
|
$form->Fields()->push(new HiddenField('Callback'));
|
||||||
|
});
|
||||||
|
// Note: A lot of scaffolding to execute the tested logic,
|
||||||
|
// due to the coupling of form creation with request handling (and its context)
|
||||||
|
$request = new GridFieldDetailForm_ItemRequest(
|
||||||
|
GridField::create('Categories', 'Categories'),
|
||||||
|
$component,
|
||||||
|
$category,
|
||||||
|
new Controller(),
|
||||||
|
'Form'
|
||||||
|
);
|
||||||
|
$form = $request->ItemEditForm();
|
||||||
|
$this->assertNotNull($form->Fields()->fieldByName('Callback'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GridFieldDetailFormTest_Person extends DataObject implements TestOnly {
|
class GridFieldDetailFormTest_Person extends DataObject implements TestOnly {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user