You are here

function flag_confirm_submit in Flag 7.3

Same name and namespace in other branches
  1. 5 flag.module \flag_confirm_submit()
  2. 6.2 flag.module \flag_confirm_submit()
  3. 6 flag.module \flag_confirm_submit()
  4. 7.2 flag.module \flag_confirm_submit()

Submit handler for the flag confirm form.

Note that validating whether the user may perform the action is done here, rather than in a form validation handler.

See also

flag_confirm()

File

includes/flag.pages.inc, line 151
Menu callbacks for the Flag module.

Code

function flag_confirm_submit(&$form, &$form_state) {
  $flag = $form['#flag'];
  $action = $form_state['values']['action'];
  $entity_id = $form_state['values']['entity_id'];
  if ($action == 'flag') {

    // If the action 'flag', further build up the new entity from form values.
    $flagging = $form['#flagging'];
    entity_form_submit_build_entity('flagging', $flagging, $form, $form_state);
    $result = $flag
      ->flag($action, $entity_id, NULL, FALSE, $flagging);
  }
  else {
    $result = $flag
      ->flag($action, $entity_id, NULL, FALSE);
  }
  if (!$result) {
    if ($errors = $flag
      ->get_errors()) {
      foreach ($errors as $error) {
        drupal_set_message($error, 'error');
      }
    }
  }
  else {
    drupal_set_message($flag
      ->get_label($action . '_message', $entity_id));
  }
}