diff --git a/modules/taxonomy.views.inc b/modules/taxonomy.views.inc index 96f9551..2968b14 100644 --- a/modules/taxonomy.views.inc +++ b/modules/taxonomy.views.inc @@ -457,14 +457,14 @@ function taxonomy_views_plugins() { 'path' => drupal_get_path('module', 'views') . '/modules/taxonomy', ), ), -// 'argument default' => array( -// 'taxonomy_tid' => array( -// 'title' => t('Taxonomy Term ID from URL'), -// 'handler' => 'views_plugin_argument_default_taxonomy_tid', -// 'path' => drupal_get_path('module', 'views') . '/modules/taxonomy', -// 'parent' => 'fixed', -// ), -// ), + 'argument default' => array( + 'taxonomy_tid' => array( + 'title' => t('Taxonomy Term ID from URL'), + 'handler' => 'views_plugin_argument_default_taxonomy_tid', + 'path' => drupal_get_path('module', 'views') . '/modules/taxonomy', + 'parent' => 'fixed', + ), + ), ); } diff --git a/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc b/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc index af1fc6c..28a7e5f 100644 --- a/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc +++ b/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc @@ -10,8 +10,7 @@ class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_d $options['term_page'] = array('default' => TRUE); $options['node'] = array('default' => FALSE); - $options['limit'] = array('default' => FALSE); - $options['vids'] = array('default' => array()); + $options['node_operator'] = array('default' => 'or'); return $options; } @@ -30,7 +29,7 @@ class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_d ); $form['node'] = array( '#type' => 'checkbox', - '#title' => t('Load default argument from node page. Good for related taxonomy blocks.'), + '#title' => t('Load default argument from node page. Useful for related taxonomy blocks.'), '#default_value' => $this->argument->options['node'], '#process' => array('views_process_dependency'), '#dependency' => array( @@ -39,83 +38,78 @@ class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_d ), '#dependency_count' => 2, ); - - $form['limit'] = array( - '#type' => 'checkbox', - '#title' => t('Limit terms by vocabulary'), - '#default_value'=> $this->argument->options['limit'], + $form['node_operator'] = array( + '#type' => 'select', + '#title' => t('How to combine term IDs'), + '#description' => t("Whether to form multiple term IDs into the argument with '+' or ','."), + '#options' => array( + 'and' => 'and', + 'or' => 'or', + ), + '#default_value' => $this->argument->options['node_operator'], '#process' => array('views_process_dependency'), '#dependency' => array( 'radio:options[default_action]' => array('default'), 'radio:options[default_argument_type]' => array($this->id), - 'edit-options-node' => array(1) + 'edit-options-node' => array(TRUE), ), '#dependency_count' => 3, ); - - $options = array(); - $vocabularies = taxonomy_get_vocabularies(); - foreach ($vocabularies as $voc) { - $options[$voc->vid] = check_plain($voc->name); - } - - $form['vids'] = array( - '#prefix' => '
', - '#suffix' => '
', - '#type' => 'checkboxes', - '#title' => t('Vocabularies'), - '#description' => t('If you wish to limit terms for specific vocabularies, check them; if none are checked, all terms will be included.'), - '#options' => $options, - '#default_value' => isset($this->argument->options['vids']) ? $this->argument->options['vids'] : array(), - '#process' => array('expand_checkboxes', 'views_process_dependency'), - '#dependency' => array( - 'radio:options[default_action]' => array('default'), - 'radio:options[default_argument_type]' => array($this->id), - 'edit-options-node' => array(1), - 'edit-options-limit' => array(1) - ), - '#dependency_count' => 4, - ); - } - - function options_submit(&$form, &$form_state, &$options) { - // Clear checkbox values. - $options['vids'] = array_filter($options['vids']); } function get_argument() { // Load default argument from taxonomy page. if (!empty($this->argument->options['term_page'])) { - if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) { - return arg(2); + if (arg(0) == 'taxonomy' && arg(1) == 'term') { + if (is_numeric(arg(2))) { + return arg(2); + } + // In case the 'Allow multiple terms per argument.' option is selected. + else if ($this->argument->options['break_phrase']) { + views_break_phrase(arg(2), $this->argument); + // Check that the error value isn't present. + if ($this->argument->value != array(-1)) { + return arg(2); + } + } } } // Load default argument from node. if (!empty($this->argument->options['node'])) { - foreach (range(1, 3) as $i) { - $node = menu_get_object('node', $i); - if (!empty($node)) { - break; - } - } - // Just check, if a node could be detected. - if ($node) { - if (!empty($this->argument->options['limit'])) { - $tids = array(); - // Filter by vid. + // First, try to get a node from the menu router system. + $node = menu_get_object('node', 1); + if (!empty($node)) { + // If our argument is set to validate the term, only pick out + // terms from the node that are in those vocabularies. + if ($this->argument->options['validate_type'] == 'taxonomy_term') { + $valid_vids = $this->argument->options['validate_argument_vocabulary']; foreach ($node->taxonomy as $tid => $term) { - if (!empty($this->argument->options['vids'][$term->vid])) { + // This has VID => VID for selected ones, and VID => 0 otherwise. + if ($valid_vids[$term->vid]) { $tids[] = $tid; } } - return implode(",", $tids); } - // Return all tids. + // Otherwise, take all terms from the node. else { - return implode(",", array_keys($node->taxonomy)); + $tids = array_keys($node->taxonomy); + } + + if ($tids) { + // Transform the argument to a string of tids, in the form + // of 1+2+3 (for OR) or 1,2,3 (for AND). + if ($this->argument->options['node_operator'] == 'and') { + $glue = ','; + } + else { + $glue = '+'; + } + + $argument_value = implode($glue, $tids); + return $argument_value; } } } + // Views will just do nothing for this argument if we end up here. } } -