public function save($data, Form $form)
 {
     if ($this->record) {
         $className = $this->getItemClassName();
         //check for an existing record
         $record = null;
         if (!empty($_REQUEST['RecordID']) && ($id = $_REQUEST['RecordID'])) {
             $record = DataObject::get_by_id($className, $id);
         }
         //if no existing record, create new record
         if (!$record) {
             $record = new $className();
         }
         $form->saveInto($record);
         try {
             $record->write();
         } catch (Exception $e) {
             $form->setMessage($e->getMessage(), 'bad');
             return ContentModuleUtilities::json_response(array("Status" => 0, "Message" => "{$className} saved successfully", "Content" => $form->forAjaxTemplate()));
         }
         $this->record->{$this->_relationship}()->add($record);
         $form->loadDataFrom($record);
         return ContentModuleUtilities::json_response(array("Status" => 1, "Message" => "{$className} saved successfully", "Content" => $this->ItemEditForm($record->ID)->forAjaxTemplate()->RAW()));
     }
     return ContentModuleUtilities::json_response(array("Status" => 0, "Message" => "Error saving"));
 }
 /**
  * Handles all actions for the individual ContentModule, action is passed on with "do" prepended
  * e.g. publish becomes ContentModule->doPublish
  *
  * @param SS_HTTPRequest $request
  * @return SS_HTTPResponse
  */
 public function module($request)
 {
     if (($action = $this->request->param('ID')) && ($id = $this->request->param('OtherID'))) {
         $module = ContentModule::get()->byID($id);
         $method = 'do' . ucfirst($action);
         if ($module && $module->hasMethod($method)) {
             $module->setCurrentModuleField($this);
             $postFields = $request->requestVar('ContentModule');
             $contentFields = !empty($postFields[$id]) ? $postFields[$id] : null;
             if (!empty($contentFields)) {
                 //set booleans to false if not set
                 //@todo this looks like a hack
                 $fields = $module->db();
                 foreach ($fields as $field => $type) {
                     if ($type == 'Boolean' && !isset($contentFields[$field])) {
                         $contentFields[$field] = false;
                     }
                 }
             }
             $message = $module->{$method}($contentFields);
             return ContentModuleUtilities::json_response(array('Status' => 1, 'Message' => $message, 'Content' => $module->EditForm()->RAW()));
         }
     }
     return ContentModuleUtilities::json_response(array('Status' => 0, 'Message' => 'There was a problem with your request'));
 }