You are here

function smartqueue_taxonomy_nodequeue_form in Nodequeue 7.2

Same name and namespace in other branches
  1. 5.2 smartqueue.module \smartqueue_taxonomy_nodequeue_form()
  2. 6.2 smartqueue.module \smartqueue_taxonomy_nodequeue_form()
  3. 7.3 smartqueue.module \smartqueue_taxonomy_nodequeue_form()

Implements hook_nodequeue_form().

File

modules/smartqueue/smartqueue.module, line 122

Code

function smartqueue_taxonomy_nodequeue_form($queue, &$form) {

  // Load data about taxonomy_term_reference fields.
  $options = array();
  $labels = array();
  $fields = field_info_fields();
  foreach ($fields as $field_name => $field_info) {
    if ($field_info['type'] == 'taxonomy_term_reference') {
      $vocabulary_name = $field_info['settings']['allowed_values'][0]['vocabulary'];
      $vocab = taxonomy_vocabulary_machine_name_load($vocabulary_name);
      $vocabulary = $vocab->name;
      foreach ($field_info['bundles'] as $entity_type => $bundles) {
        foreach ($bundles as $bundle) {
          $instance = field_info_instance($entity_type, $field_name, $bundle);
          if (isset($labels[$instance['label']])) {
            $count = $labels[$instance['label']];
            $count++;
          }
          else {
            $count = 1;
          }
          $labels[$field_name][$instance['label']] = $count;
        }
      }
      asort($labels[$field_name]);
      $labels_copy = $labels[$field_name];
      $labels_inverted = array_flip($labels_copy);
      $label = array_pop($labels_inverted);
      $options[$field_name] = t('@label (%field-name), selecting terms from vocabulary: @vocabulary.', array(
        '@label' => $label,
        '%field-name' => $field_name,
        '@vocabulary' => $vocabulary,
      ));
    }
  }
  $form['placeholder']['taxonomy_fields'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Taxonomy term reference fields'),
    '#description' => t('Each unique combination of terms from all of these fields will have a subqueue.'),
    '#options' => $options,
  );
  $form['placeholder']['use_parents'] = array(
    '#type' => 'checkbox',
    '#title' => t('Assume parent term for hierarchical vocabs'),
    '#description' => t("Instead of using the node's terms for nodequeue assignment use the top-most parents of a term. This has no effect if there in non-hierarchical vocabularies."),
    '#default_value' => isset($queue->use_parents) ? $queue->use_parents : 0,
  );
  $form['placeholder']['use_parents_all'] = array(
    '#type' => 'checkbox',
    '#title' => t('Assume all ancestor terms for hierarchical vocabs'),
    '#description' => t("Instead of using just the node's terms for nodequeue assignment use all the ancestors of a term in addition. This has no effect if there in non hierarchical vocabularies."),
    '#default_value' => isset($queue->use_parents_all) ? $queue->use_parents_all : 0,
  );
  $form['subqueue_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Subqueue title'),
    '#default_value' => $queue->subqueue_title,
    '#size' => 50,
    '#maxlength' => 64,
    '#description' => t('Use <em>%subqueue</em> to embed the subqueue title. This is used to distinguish multiple nodequeues with subqueues from each other.'),
  );

  // Change reference field into our saved format.
  if (!empty($queue->qid)) {
    $form['placeholder']['taxonomy_fields']['#disabled'] = TRUE;
    $form['placeholder']['taxonomy_fields']['#default_value'] = explode('-', $queue->reference);
  }
}