diff -rupN ../views/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc ./modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc
--- ../views/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc 2011-03-18 10:58:55.000000000 +1100
+++ ./modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc 2011-03-19 16:50:38.000000000 +1100
@@ -5,117 +5,22 @@
*/
class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_default {
- function option_definition() {
- $options = parent::option_definition();
-
- $options['term_page'] = array('default' => TRUE);
- $options['node'] = array('default' => FALSE);
- $options['limit'] = array('default' => FALSE);
- $options['vids'] = array('default' => array());
-
- return $options;
- }
-
- function argument_form(&$form, &$form_state) {
- $form['term_page'] = array(
- '#type' => 'checkbox',
- '#title' => t('Load default argument from term page'),
- '#default_value' => $this->argument->options['term_page'],
- '#process' => array('views_process_dependency'),
- '#dependency' => array(
- 'radio:options[default_action]' => array('default'),
- 'radio:options[default_argument_type]' => array($this->id)
- ),
- '#dependency_count' => 2,
- );
- $form['node'] = array(
- '#type' => 'checkbox',
- '#title' => t('Load default argument from node page. Good for related taxonomy blocks.'),
- '#default_value' => $this->argument->options['node'],
- '#process' => array('views_process_dependency'),
- '#dependency' => array(
- 'radio:options[default_action]' => array('default'),
- 'radio:options[default_argument_type]' => array($this->id)
- ),
- '#dependency_count' => 2,
- );
-
- $form['limit'] = array(
- '#type' => 'checkbox',
- '#title' => t('Limit terms by vocabulary'),
- '#default_value'=> $this->argument->options['limit'],
- '#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)
- ),
- '#dependency_count' => 3,
- );
-
- $options = array();
- $vocabularies = taxonomy_get_vocabularies();
- foreach ($vocabularies as $voc) {
- $options[$voc->vid] = check_plain($voc->name);
- }
-
- $form['vids'] = array(
- '#prefix' => '
',
- '#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))) {
+ if (arg(0) == 'taxonomy' && arg(1) == 'term') {
+ if (is_numeric(arg(2))) {
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.
- foreach ($node->taxonomy as $tid => $term) {
- if (!empty($this->argument->options['vids'][$term->vid])) {
- $tids[] = $tid;
- }
- }
- return implode(",", $tids);
- }
- // Return all tids.
- else {
- return implode(",", array_keys($node->taxonomy));
+ // 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 (!in_array(-1, $this->argument->value)) {
+ return arg(2);
}
}
}
+ // Views will just do nothing for this argument if we end up here.
}
}
-
diff -rupN ../views/modules/taxonomy/views_plugin_argument_default_taxonomy_tid_node.inc ./modules/taxonomy/views_plugin_argument_default_taxonomy_tid_node.inc
--- ../views/modules/taxonomy/views_plugin_argument_default_taxonomy_tid_node.inc 1970-01-01 10:00:00.000000000 +1000
+++ ./modules/taxonomy/views_plugin_argument_default_taxonomy_tid_node.inc 2011-03-19 17:11:18.000000000 +1100
@@ -0,0 +1,77 @@
+ 'or');
+
+ return $options;
+ }
+
+ /**
+ * Provide extra options for this default argument.
+ */
+ function argument_form(&$form, &$form_state) {
+ $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' => isset($this->argument->options['node_operator']) ? $this->argument->options['node_operator'] : 'or',
+ '#process' => array('views_process_dependency'),
+ '#dependency' => array(
+ 'radio:options[default_action]' => array('default'),
+ 'radio:options[default_argument_type]' => array($this->id),
+ ),
+ '#dependency_count' => 2,
+ );
+ }
+
+ /**
+ * Get an argument from the current node's taxonomy terms.
+ */
+ function get_argument() {
+ // 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) {
+ // This has VID => VID for selected ones, and VID => 0 otherwise.
+ if ($valid_vids[$term->vid]) {
+ $tids[] = $tid;
+ }
+ }
+ }
+ // Otherwise, take all terms from the node.
+ else {
+ $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.
+ }
+}
diff -rupN ../views/modules/taxonomy.views.inc ./modules/taxonomy.views.inc
--- ../views/modules/taxonomy.views.inc 2011-03-18 10:58:55.000000000 +1100
+++ ./modules/taxonomy.views.inc 2011-03-19 16:50:38.000000000 +1100
@@ -457,14 +457,20 @@ 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 term page URL'),
+ 'handler' => 'views_plugin_argument_default_taxonomy_tid',
+ 'path' => drupal_get_path('module', 'views') . '/modules/taxonomy',
+ 'parent' => 'fixed',
+ ),
+ 'taxonomy_tid_node' => array(
+ 'title' => t('Taxonomy Term ID from current node'),
+ 'handler' => 'views_plugin_argument_default_taxonomy_tid_node',
+ 'path' => drupal_get_path('module', 'views') . '/modules/taxonomy',
+ 'parent' => 'fixed',
+ ),
+ ),
);
}