If you work with DataObject
s and GridField
s a lot in SilverStripe, it can be time
consuming hunting down all instances where an object can be edited and swap them out
with a custom edit form.
This simple module allows you to change the GridFieldDetailFormItemRequest class used by
GridFieldDetailForm
via a simple config variable (set on the record being edited).
This then automatically updates the GridFieldDetailForm
in all areas the record is
edited in a GridField
First off you need to create a custom edit form to be loaded into your GridFields. Something like:
namespace App\Forms;
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
class CustomDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest
{
/**
* Customise the default edit form generated by SilverStripe
*
* @return Form|HTTPResponse
*/
public function ItemEditForm()
{
$form = parent::ItemEditForm();
//... Customise your edit form
return $form;
}
}
Once you have done this, simply add the gridfield_request_class
config variable to
your DataObject
and then this module will swap out the GridFieldDetailForm_ItemRequest
class automatically in all GridField
s:
namespace App\Model\Submissions;
use SilverStripe\ORM\DataObject;
use App\Forms\CustomDetailForm_ItemRequest;
class MyDataObject extends DataObject
{
private static $table_name = "MyDataObject";
private static $db = [
'Name' => 'Varchar',
'Description' => 'HTMLText',
];
private static $gridfield_request_class = CustomDetailForm_ItemRequest::class;
}