/** * Handles the given action context. * * @param GridField $gridField GridField to handle action for * @param string $actionName Name of the action to handle * @param array $arguments Arguments * @param array $data Post data to handle * * @return string * * @author Sebastian Diel <*****@*****.**> * @since 14.03.2013 */ public function handleAction(GridField $gridField, $actionName, $arguments, $data) { if ($actionName == 'addsubobject') { $recordID = $data['SubObjectParentID']; $subObjectID = $data[$gridField->getModelClass() . 'SubObjects'][$recordID]; $list = $gridField->getList(); $parent = DataObject::get($gridField->getModelClass())->byID($recordID); $subObject = DataObject::get($this->targetClassName)->byID($subObjectID); if ($subObject instanceof $this->targetClassName && $subObject->exists()) { $this->subList->add($subObject); } } elseif ($actionName == 'removesubobject' || $actionName == 'activatesubobject' || $actionName == 'deactivatesubobject' || $actionName == 'defaultsubobject' || $actionName == 'undefaultsubobject') { $recordID = $data['SubObjectParentID']; $subObjectID = $data['SubObjectID']; $list = $gridField->getList(); $parent = DataObject::get($gridField->getModelClass())->byID($recordID); $subObject = DataObject::get($this->targetClassName)->byID($subObjectID); if ($subObject instanceof $this->targetClassName && $subObject->exists()) { if ($actionName == 'defaultsubobject' || $actionName == 'undefaultsubobject') { $this->subList->add($subObject, array('IsDefault' => $actionName == 'defaultsubobject')); } elseif ($actionName == 'activatesubobject' || $actionName == 'deactivatesubobject') { $this->subList->add($subObject, array('IsActive' => $actionName == 'activatesubobject')); } elseif ($actionName == 'removesubobject') { $this->subList->remove($subObject); } } } }