You are here

function flag_lists_form_submit in Flag Lists 7

Same name and namespace in other branches
  1. 6 flag_lists.admin.inc \flag_lists_form_submit()
  2. 7.3 flag_lists.admin.inc \flag_lists_form_submit()

Save a list.

1 call to flag_lists_form_submit()
flag_lists_generate_lists_form_submit in ./flag_lists.admin.inc
Submit handler for flag_lists_generate_lists_form.

File

./flag_lists.admin.inc, line 230
Contains administrative pages for creating, editing, and deleting flag lists.

Code

function flag_lists_form_submit($form, $form_state, $account = NULL) {
  if (!isset($account)) {
    $account = $GLOBALS['user'];
  }
  if (!empty($form_state['values']['edit'])) {

    // Editing the title.
    $flag = flag_lists_get_flag($form_state['values']['name']);
    $flag->title = $form_state['values']['title'];
    flag_lists_set_messages($flag);
    flag_lists_save($flag);
    _flag_lists_clear_cache();
  }
  else {

    // New flag. Load the template row.
    $type = $form_state['values']['type'];
    $query = db_select('flags', 'f');
    $query
      ->leftJoin('flag_lists_types', 'fl', 'f.name = fl.name');
    $query
      ->fields('f')
      ->fields('fl')
      ->condition('fl.type', $type);
    $row = $query
      ->execute()
      ->fetchObject();
    $newflag = flag_flag::factory_by_content_type('node');
    $flag = $newflag
      ->factory_by_row($row);

    // The template fid becomes the flag_lists parent flag.
    $flag->pfid = $row->fid;

    // The fid is NULL because this is really a new flag.
    $flag->fid = NULL;

    // The name is created in the save function.
    $flag->name = NULL;
    $flag->link_type = 'toggle';
    $flag->title = $form_state['values']['title'];
    $flag->types = array(
      $type,
    );
    $flag->uid = $account->uid;
    flag_lists_set_messages($flag);

    // Save it.
    flag_lists_save($flag, $account);
  }
}