You are here

function flag_lists_form in Flag Lists 7

Same name and namespace in other branches
  1. 6 flag_lists.admin.inc \flag_lists_form()
  2. 7.3 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 146
Contains administrative pages for creating, editing, and deleting flag lists.

Code

function flag_lists_form($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_select('flag_lists_flags', 'f')
      ->fields('f', array(
      'name',
    ))
      ->condition('fid', $name)
      ->execute()
      ->fetchField();
  }

  // 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);
    $title_string_name = variable_get('flag_lists_name', 'list');
    $title_string = t('Edit your "@title" @name title', array(
      '@title' => $flag
        ->get_title(),
      '@name' => $title_string_name,
    ));
    drupal_set_title();
    $form['edit'] = array(
      '#type' => 'hidden',
      '#value' => TRUE,
    );
    $form['name'] = array(
      '#type' => 'hidden',
      '#value' => $name,
    );
  }
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => empty($flag->title) ? '' : $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;
}