You are here

function nodequeue_edit_queue_form in Nodequeue 7.2

Same name and namespace in other branches
  1. 5.2 nodequeue.module \nodequeue_edit_queue_form()
  2. 6.2 includes/nodequeue.admin.inc \nodequeue_edit_queue_form()
  3. 7.3 includes/nodequeue.admin.inc \nodequeue_edit_queue_form()

Add or edit a queue.

1 string reference to 'nodequeue_edit_queue_form'
nodequeue_menu in ./nodequeue.module
Implements hook_menu().

File

includes/nodequeue.admin.inc, line 383
Admin page callbacks for the nodequeue module.

Code

function nodequeue_edit_queue_form($form, &$form_state, $queue) {
  $info = nodequeue_api_info();

  // For adding queues.
  if (is_string($queue)) {

    // If the $queue is a string - name of a queue type, basically - then we test that it's a valid queue type.
    $queue = strtolower($queue);
    if (!isset($info[$queue])) {
      return FALSE;
    }
    drupal_set_title(t('Add @type', array(
      '@type' => $info[$queue]['title'],
    )), PASS_THROUGH);
    $queue = new nodequeue_queue($queue);
  }
  else {
    drupal_set_title(t("Nodequeue '@title'", array(
      '@title' => $queue->title,
    )), PASS_THROUGH);
  }
  $form['description'] = array(
    '#type' => 'fieldset',
    '#title' => filter_xss($info[$queue->owner]['title']),
    '#description' => filter_xss($info[$queue->owner]['description']),
  );
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $queue->title,
    '#size' => 50,
    '#required' => TRUE,
    '#maxlength' => 64,
  );
  $form['name'] = array(
    '#type' => 'machine_name',
    '#maxlength' => 32,
    '#machine_name' => array(
      'exists' => 'nodequeue_machine_name_exists',
      'source' => array(
        'title',
      ),
    ),
    '#description' => t('A unique machine-readable name for this queue. It must only contain lowercase letters, numbers, and underscores.'),
  );
  if (!empty($queue->name)) {
    $form['name']['#default_value'] = $queue->name;
    $form['name']['#disabled'] = TRUE;
    $form['name']['#value'] = $queue->name;
  }

  // This is a value; as the default nodequeue implementation has just one
  // queue per nodequeue, this field is totally redundant. Plugins can
  // override this.
  $form['subqueue_title'] = array(
    '#type' => 'value',
    '#value' => $queue->subqueue_title,
  );

  // The placeholder is put here so that modifiers have an easy way to put
  // additional form widgets in a prominent spot but not before the title of
  // the queue.
  $form['placeholder'] = array();
  $form['size'] = array(
    '#type' => 'textfield',
    '#title' => t('Queue size'),
    '#default_value' => $queue->size,
    '#size' => 2,
    '#maxlength' => 3,
    '#required' => TRUE,
    '#description' => t('The maximum number of nodes will appear in the queue. Enter 0 for no limit'),
  );
  $form['reverse'] = array(
    '#type' => 'checkbox',
    '#title' => t('Reverse in admin view'),
    '#default_value' => $queue->reverse,
    '#description' => t('Ordinarily queues are arranged with the front of the queue (where items will be removed) on top and the back (where items will be added) on the bottom. If checked, this will display the queue such that items will be added to the top and removed from the bottom.'),
  );
  $form['insert_at_front'] = array(
    '#type' => 'checkbox',
    '#title' => t('Insert nodes at front of queue, and delete from the back.'),
    '#default_value' => $queue->insert_at_front,
    '#description' => t('Ordinarily items are added at the back of the queue, and excess nodes are removed from the front. If checked, this behaviour is reversed: nodes will be added at the front and removed from the back.'),
  );
  $form['unique_entries'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enforce uniqueness.'),
    '#default_value' => !empty($queue->unique_entries),
    '#description' => t('Ensure that the same node can only exist once in a subqueue.'),
  );
  $form['link'] = array(
    '#type' => 'textfield',
    '#title' => t('Link "add to queue" text'),
    '#default_value' => $queue->link,
    '#size' => 64,
    '#maxlength' => 64,
    '#description' => t('If you want a link to add a node to a queue in the "links" section (next to "add new comment"), enter the text here. If left blank no link will be given; note that enabling this feature for any queue will cause an extra query to be run every time a node is loaded. "%subqueue" will be replaced with the subqueue title, if applicable.'),
  );
  $form['link_remove'] = array(
    '#type' => 'textfield',
    '#title' => t('Link "remove from queue" text'),
    '#default_value' => $queue->link_remove,
    '#size' => 64,
    '#maxlength' => 64,
    '#description' => t('Enter the text for the corresponding link to remove a node from a queue. This may be blank (in which case no link will appear) but a remove link will only appear if link, above, is set.'),
  );
  $manipulate_all_queues = user_roles(FALSE, 'manipulate all queues');
  $manipulate_queues = user_roles(FALSE, 'manipulate queues');
  $roles = $manipulate_all_queues + $manipulate_queues;
  if (!empty($roles)) {
    $form['roles'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Roles that can add nodes to this queue'),
      '#default_value' => is_array($queue->roles) ? $queue->roles : array(),
      '#options' => $roles,
      '#description' => t('Check each role that can add nodes to the queue. Be sure that roles you want to appear here have "manipulate queues" access in the main access control panel.'),
    );
    foreach ($roles as $rid => $role) {
      $form['roles'][$rid] = array(
        '#type' => 'checkbox',
        '#title' => $role,
        '#default_value' => isset($manipulate_all_queues[$rid]) || in_array($rid, $queue->roles) ? TRUE : FALSE,
        '#disabled' => isset($manipulate_all_queues[$rid]) ? TRUE : FALSE,
      );
    }
  }
  else {
    $form['roles'] = array(
      '#type' => 'value',
      '#value' => array(),
    );
    $form['roles_markup'] = array(
      '#type' => 'item',
      '#title' => t('Roles'),
      '#description' => '<strong>' . t('No roles have the "manipulate queues" permission, so only the administrator account will be able to add or remove items from this queue.') . '</strong>',
    );
  }
  $nodes = node_type_get_names();
  $form['types'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Content types that can be added to this queue'),
    '#default_value' => $queue->types,
    '#options' => $nodes,
  );
  $form['i18n'] = array(
    '#type' => 'radios',
    '#title' => t('Internationalization'),
    '#options' => array(
      '1' => t('Treat translation nodes as a single node'),
      '0' => t('Manually manage translated nodes'),
    ),
    '#default_value' => empty($queue->qid) && module_exists('translation') ? 0 : $queue->i18n,
    '#description' => t('Treating translations as a single node allows users to add, remove and manipulate a node
      in the queue regardless of which translation is acted upon; nodequeue will only act on the original node.
      When manually managing translation nodes, Nodequeue will ignore the relationship between node translations;
      each translation node must be added to the queue separately and will occupy a separate spot in the queue.
      Changing this setting will <strong>not</strong> update content that is already in the queue.'),
    '#access' => module_exists('translation'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#attributes' => array(
      'class' => array(
        'button-primary',
      ),
    ),
  );
  $form['owner'] = array(
    '#type' => 'value',
    '#value' => $queue->owner,
  );
  $form['show_in_links'] = array(
    '#type' => 'value',
    '#value' => $queue->show_in_links,
  );
  $form['show_in_tab'] = array(
    '#type' => 'value',
    '#value' => $queue->show_in_tab,
  );
  $form['show_in_ui'] = array(
    '#type' => 'value',
    '#value' => $queue->show_in_ui,
  );
  $form['reference'] = array(
    '#type' => 'value',
    '#value' => $queue->reference,
  );
  $form['subqueues'] = array(
    '#type' => 'value',
    '#value' => $queue->subqueues,
  );
  if (isset($queue->qid)) {
    $form['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#validate' => array(
        'nodequeue_edit_queue_form_delete_validate',
      ),
      '#submit' => array(
        'nodequeue_edit_queue_form_delete_submit',
      ),
    );
    $form['qid'] = array(
      '#type' => 'value',
      '#value' => $queue->qid,
    );
    $form['count'] = array(
      '#type' => 'value',
      '#value' => $queue->count,
    );
  }
  nodequeue_api_queue_form($queue, $form);
  return $form;
}