ENHANCEMENT: Add grid field save handler.

This commit is contained in:
Andrew Short 2013-01-15 22:41:25 +11:00
parent 27d2f75d9d
commit 16efd7402e
3 changed files with 30 additions and 0 deletions

View File

@ -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

View File

@ -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);
}
}
}
}

View File

@ -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);
}