You are here

function flag_lists_form_submit in Flag Lists 6

Same name and namespace in other branches
  1. 7.3 flag_lists.admin.inc \flag_lists_form_submit()
  2. 7 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 155
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 ($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'];
    $row = db_fetch_object(db_query("SELECT * from {flags} f LEFT JOIN {flag_lists_types} fl on f.name = fl.name WHERE fl.type = '%s'", $type));
    $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);
  }
}