You are here

function views_bulk_operations_taxonomy_action_form in Views Bulk Operations (VBO) 6

Same name and namespace in other branches
  1. 6.3 taxonomy.action.inc \views_bulk_operations_taxonomy_action_form()

File

actions/taxonomy.action.inc, line 117

Code

function views_bulk_operations_taxonomy_action_form($context) {
  if (isset($context['selection']) && isset($context['view'])) {
    $vocabularies = array();
    $nids = array_map('_views_bulk_operations_get_oid', $context['selection'], array_fill(0, count($context['selection']), $context['view']->base_field));
    $placeholders = db_placeholders($nids);
    $result = db_query("SELECT DISTINCT v.vid FROM {vocabulary_node_types} v LEFT JOIN {node} n ON v.type = n.type WHERE n.nid IN ({$placeholders})", $nids);
    while ($v = db_fetch_object($result)) {
      $vocabularies[$v->vid] = taxonomy_vocabulary_load($v->vid);
    }
  }
  else {
    $vocabularies = taxonomy_get_vocabularies();
  }
  if (empty($vocabularies)) {
    drupal_set_message(t('The selected nodes are not associated with any vocabulary. Please select other nodes and try again.'), 'error');
    return array();
  }
  $form['taxonomy'] = array(
    '#type' => 'fieldset',
    '#title' => t('Vocabularies'),
    '#tree' => TRUE,
  );
  while (list(, $vocabulary) = each($vocabularies)) {
    $form['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, isset($context['terms']) ? $context['terms'] : NULL);
    $form['taxonomy'][$vocabulary->vid]['#weight'] = $vocabulary->weight;
    if ($vocabulary->tags) {

      // If tags, give the ability to add new terms
      if ($vocabulary->help) {
        $help = filter_xss_admin($vocabulary->help);
      }
      else {
        $help = t('A comma-separated list of terms describing this content. Example: funny, bungee jumping, "Company, Inc.".');
      }
      $help .= t('<br />Note that this field has no effect when deleting terms.');
      $form['taxonomy']['tags'][$vocabulary->vid] = array(
        '#type' => 'textfield',
        '#title' => $vocabulary->name . ' ' . t('(new tags)'),
        '#autocomplete_path' => 'taxonomy/autocomplete/' . $vocabulary->vid,
        '#weight' => $vocabulary->weight,
        '#maxlength' => 1024,
        '#description' => $help,
        '#default_value' => isset($context['terms']['tags'][$vocabulary->vid]) ? $context['terms']['tags'][$vocabulary->vid] : '',
      );
    }
  }
  $form['do'] = array(
    '#type' => 'radios',
    '#title' => t('Action to take'),
    '#default_value' => isset($context['do']) ? $context['do'] : TAXONOMY_ACTION_ADD,
    '#options' => array(
      TAXONOMY_ACTION_ADD => t('Add the selected terms'),
      TAXONOMY_ACTION_REPLACE => t('Replace existing terms with selected ones'),
      TAXONOMY_ACTION_REPLACE_VOCABULARY => t('Replace terms within same vocabulary'),
      TAXONOMY_ACTION_DELETE => t('Delete selected terms'),
    ),
    '#required' => TRUE,
    '#weight' => -2,
    '#description' => t('Note that <strong>Replace existing terms with selected ones</strong> will cause all existing terms on the node to be deleted first,
                         then the new, selected terms will be added. <strong>Replace terms within same vocabulary</strong> will delete existing terms within
                         the selected terms\' vocabularies only, and will leave other existing terms untouched.'),
  );
  return $form;
}