You are here

function flag_actions_form_submit in Flag 7.2

Same name and namespace in other branches
  1. 5 flag_actions.module \flag_actions_form_submit()
  2. 6.2 flag_actions.module \flag_actions_form_submit()
  3. 6 flag_actions.module \flag_actions_form_submit()
  4. 7.3 flag_actions.module \flag_actions_form_submit()

Generic submit handler for saving flag actions.

File

./flag_actions.module, line 559
Actions support for the Flag module.

Code

function flag_actions_form_submit($form, &$form_state) {

  // If simply gathering the callback, save it to form state storage and
  // rebuild the form to gather the complete information.
  if ($form_state['values']['new']) {
    $form_state['storage']['callback'] = $form_state['values']['callback'];
    $form_state['rebuild'] = TRUE;
    return;
  }
  $aid = $form_state['values']['flag']['aid'];
  $flag = $form_state['values']['flag']['flag'];
  $event = $form_state['values']['flag']['event'];
  $threshold = $form_state['values']['flag']['threshold'];
  $repeat_threshold = $form_state['values']['flag']['repeat_threshold'];
  $callback = $form_state['values']['flag']['callback'];

  // Specialized forms may need to execute their own submit handlers on save.
  $submit_function = $callback . '_submit';
  $parameters = function_exists($submit_function) ? $submit_function($form, $form_state) : array();
  if (empty($aid)) {
    $aid = flag_actions_insert_action($flag->fid, $event, $threshold, $repeat_threshold, $callback, $parameters);
    $form_state['values']['flag']['aid'] = $aid;
    $form_state['values']['flag']['is_new'] = TRUE;
  }
  else {
    flag_actions_update_action($aid, $event, $threshold, $repeat_threshold, $parameters);
  }
  $action = flag_actions_get_action($aid);
  drupal_set_message(t('The "@action" action for the @title flag has been saved.', array(
    '@action' => $action->label,
    '@title' => $flag
      ->get_title(),
  )));
  $form_state['redirect'] = FLAG_ADMIN_PATH . '/actions';
}