Example #1
0
 /**
  * The callback used by the form class. This callback is only called when
  * the add or edit controller actions are performed. 
  * 
  * @param array $data The data from the form
  * @param Form $form an instance of the form
  * @param \ModelController $instance Specific data from the form, this normally includes an instance of the controller
  * 
  * @see ModelController::$callbackFunction
  * @return boolean
  */
 public static function callback($data, $form, $instance)
 {
     $key = $instance->model->getKeyField();
     $return = $instance->model->setData($data, $key, $instance->currentItemId);
     $entity = Utils::singular($instance->model->getEntity());
     if ($return === true) {
         if ($instance->actionMethod === 'add') {
             $id = $instance->model->save();
             Application::queueNotification($instance->getAddNotificationMessage($entity, $instance->model));
         } else {
             $id = $instance->model->update($key, $instance->currentItemId);
             Application::queueNotification($instance->getUpdateNotificationMessage($entity, $instance->model));
         }
         Application::redirect($instance->urlPath);
     } else {
         self::setFormErrors($form, $return['errors']);
     }
 }