mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT: Add grid field save handler.
This commit is contained in:
parent
27d2f75d9d
commit
16efd7402e
@ -303,6 +303,12 @@ This object is used for creating actions buttons, for example a delete button. W
|
||||
a FormAction, the gridfield finds a `GridField_ActionProvider` that listens on that action.
|
||||
`GridFieldDeleteAction` have a pretty basic implementation of how to use a Form action.
|
||||
|
||||
## GridField_SaveHandler
|
||||
|
||||
This is used to create a handler that is called when a form containing the grid
|
||||
field is saved into a record. This is useful for performing actions when saving
|
||||
the record.
|
||||
|
||||
### GridState
|
||||
|
||||
Gridstate is a class that is used to contain the current state and actions on the gridfield. It's
|
||||
|
@ -727,6 +727,15 @@ class GridField extends FormField {
|
||||
|
||||
return parent::handleRequest($request, $model);
|
||||
}
|
||||
|
||||
public function saveInto(DataObjectInterface $record) {
|
||||
foreach($this->getComponents() as $component) {
|
||||
if($component instanceof GridField_SaveHandler) {
|
||||
$component->handleSave($this, $record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -142,3 +142,18 @@ interface GridField_URLHandler extends GridFieldComponent {
|
||||
*/
|
||||
public function getURLHandlers($gridField);
|
||||
}
|
||||
|
||||
/**
|
||||
* A component which is used to handle when a grid field is saved into a record.
|
||||
*/
|
||||
interface GridField_SaveHandler extends GridFieldComponent {
|
||||
|
||||
/**
|
||||
* Called when a grid field is saved - i.e. the form is submitted.
|
||||
*
|
||||
* @param GridField $field
|
||||
* @param DataObjectInterface $record
|
||||
*/
|
||||
public function handleSave(GridField $grid, DataObjectInterface $record);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user