Permalink
Browse files

ENHANCEMENT: Add grid field save handler.

  • Loading branch information...
1 parent 27d2f75 commit 16efd7402eac9319bd8e5d7a3e34e645650ff1ca @ajshort ajshort committed Jan 15, 2013
Showing with 30 additions and 0 deletions.
  1. +6 −0 docs/en/reference/grid-field.md
  2. +9 −0 forms/gridfield/GridField.php
  3. +15 −0 forms/gridfield/GridFieldComponent.php
@@ -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 @@ public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
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 @@ public function getManipulatedData(GridField $gridField, SS_List $dataList);
*/
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);
+
+}

0 comments on commit 16efd74

Please sign in to comment.