You are here

function flag_lists_form in Flag Lists 6

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

Form to Add or edit a list.

2 string references to 'flag_lists_form'
flag_lists_add in ./flag_lists.admin.inc
flag_lists_menu in ./flag_lists.module
Implementation of hook_menu().

File

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

Code

function flag_lists_form(&$form_state, $name = NULL, $type = NULL) {

  // First some sanity checks. $name and $type can't both be NULL.
  // There must be a template for this content type.
  if (is_null($name) && is_null($type)) {
    drupal_access_denied();
  }
  if (!flag_lists_template_exists($type) && is_null($name)) {
    return;
  }

  // If name is numeric, then we have the fid, so get the name.
  if (is_numeric($name)) {
    $name = db_result(db_query("SELECT name from {flag_lists_flags} WHERE fid = %s", $name));
  }

  // Adding a new list.
  if (!isset($name)) {
    drupal_set_title(t('Add a new list'));
    $form['edit'] = array(
      '#type' => 'hidden',
      '#value' => FALSE,
    );
  }
  else {
    $flag = flag_lists_get_flag($name);
    drupal_set_title(t('Edit your "@title" @name title', array(
      '@title' => $flag
        ->get_title(),
      '@name' => variable_get('flag_lists_name', t('list')),
    )));
    $form['edit'] = array(
      '#type' => 'hidden',
      '#value' => TRUE,
    );
    $form['name'] = array(
      '#type' => 'hidden',
      '#value' => $name,
    );
  }
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $flag->title,
    '#description' => t('A short, descriptive title for this @name list. Limit to 255 characters.', array(
      '@name' => variable_get('flag_lists_name', t('list')),
    )),
    '#maxlength' => 255,
    '#required' => TRUE,
    '#access' => empty($flag->locked['title']),
    '#weight' => -2,
  );
  $form['type'] = array(
    '#type' => 'hidden',
    '#value' => $type,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}