From 74d6206b0d28332c4919fd4d48ce3d3f8397d52f Mon, 2 May 2011 12:34:17 -0500
From: jastraat <jastraat@105111.no-reply.drupal.org>
Date: Mon, 2 May 2011 12:33:04 -0500
Subject: [PATCH] #1101432 re-roll

diff --git a/plugins/access/term.inc b/plugins/access/term.inc
index 043f421..aa50e01 100644
--- a/plugins/access/term.inc
+++ b/plugins/access/term.inc
@@ -13,7 +13,7 @@
   'title' => t("Taxonomy: term"),
   'description' => t('Control access by a specific term.'),
   'callback' => 'ctools_term_ctools_access_check',
-  'default' => array('vids' => array()),
+  'default' => array('vid' => array()),
   'settings form' => 'ctools_term_ctools_access_settings',
   'settings form validation' => 'ctools_term_ctools_access_settings_validate',
   'settings form submit' => 'ctools_term_ctools_access_settings_submit',
@@ -59,30 +59,23 @@
     $options[$vid] = $vocabulary->name;
     $form['settings'][$vocabulary->vid] = array(
       '#title' => t('Terms'),
-      '#description' => t('Select a term or terms from @vocabulary.', array('@vocabulary' => $vocabulary->name)), //. $description,
+      '#description' => t('Select a term or terms from @vocabulary.', array('@vocabulary' => $vocabulary->name)),
       '#dependency' => array('ctools-select-vid' => array($vocabulary->vid)),
       '#default_value' => !empty($conf[$vid]) ? $conf[$vid] : '',
-      '#multiple' => TRUE,
     );
 
-    // If it's a tag, use an autocomplete.
-    if ($vocabulary->tags) {
-      $form['settings'][$vocabulary->vid]['#type'] = 'textfield';
-      $form['settings'][$vocabulary->vid]['#autocomplete_path'] = 'taxonomy/autocomplete/' . $vocabulary->vid;
+    foreach (taxonomy_get_tree($vocabulary->vid) as $tid => $term) {
+      $terms[$term->tid] = str_repeat('-', $term->depth) . ($term->depth ? ' ' : '') . $term->name;
     }
-
-    // Other vocabs just show a list.
-    else {
-      $terms = array();
-      foreach (taxonomy_get_tree($vid) as $x => $term) {
-        $terms[$term->tid] = str_repeat('-', $term->depth) . ($term->depth ? ' ' : '') . $term->name;
-      }
-      $form['settings'][$vocabulary->vid]['#type'] = 'select';
-      $form['settings'][$vocabulary->vid]['#options'] = $terms;
-      unset($terms);
-    }
+    $form['settings'][$vocabulary->vid]['#type'] = 'select';
+    $form['settings'][$vocabulary->vid]['#options'] = $terms;
+    $form['settings'][$vocabulary->vid]['#multiple'] = TRUE;
+    // @todo: Remove this workaround when {@see: http://drupal.org/node/1117526} is in core.
+    $form['settings'][$vocabulary->vid]['#name'] = 'settings['.$vid.'][]';
+    $form['settings'][$vocabulary->vid]['#attributes'] = array('multiple' => 'multiple');
+    unset($terms);
+    $form['settings']['vid']['#options'] = $options;
   }
-  $form['settings']['vid']['#options'] = $options;
   return $form;
 }
 
@@ -108,39 +101,27 @@
   }
 
   $return = FALSE;
-  // Tags get saved as an imploded array of strings.
-  if (!is_array($conf[$vid])) {
-    $terms = explode(', ', $conf[$vid]);
-    // For multi-term with names, we'll only accept the first term because
-    // that is the name we have.
-    return in_array($context->data->name, $terms);
+
+  $terms = array_filter($conf[$vid]);
+  // For multi-term if any terms coincide, let's call that good enough:
+  if (isset($context->tids)) {
+    return (bool) array_intersect($conf[$vid], $context->tids);
   }
   else {
-    $terms = array_filter($conf[$vid]);
-    // For multi-term if any terms coincide, let's call that good enough:
-    if (isset($context->tids)) {
-      return (bool) array_intersect($terms, $context->tids);
-    }
-    else {
-      return in_array($context->data->tid, $terms);
-    }
+    return in_array($context->data->tid, $conf[$vid]);
   }
+  return FALSE;
 }
 
 /**
  * Provide a summary description based upon the checked terms.
  */
 function ctools_term_ctools_access_summary($conf, $context) {
-  $vocab = taxonomy_vocabulary_load($conf['vid']);
-  if ($vocab->tags) {
-    $terms = explode(', ', $conf[$vocab->vid]);
-  }
-  else {
-    $terms = array();
-    foreach ($conf[$vocab->vid] as $tid) {
-      $term = taxonomy_term_load($tid);
-      $terms[] = $term->name;
-    }
+  $vid = $conf['vid'];
+  $terms = array();
+  foreach ($conf[$vid] as $tid) {
+    $term = taxonomy_term_load($tid);
+    $terms[] = $term->name;
   }
 
   return format_plural(count($terms),
