Created
October 30, 2014 04:14
-
-
Save cafuego/9419f7c89c6443aaa0cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/views/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc b/app/profiles/cod/modules/contrib/views/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc | |
index 9c1d81f..431a567 100644 | |
--- a/views/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc | |
+++ b/views/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc | |
@@ -28,6 +28,7 @@ class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_d | |
$options['term_page'] = array('default' => TRUE, 'bool' => TRUE); | |
$options['node'] = array('default' => FALSE, 'bool' => TRUE); | |
+ $options['user'] = array('default' => FALSE, 'bool' => TRUE); | |
$options['anyall'] = array('default' => ','); | |
$options['limit'] = array('default' => FALSE, 'bool' => TRUE); | |
$options['vocabularies'] = array('default' => array()); | |
@@ -46,6 +47,11 @@ class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_d | |
'#title' => t('Load default filter from node page, that\'s good for related taxonomy blocks'), | |
'#default_value' => $this->options['node'], | |
); | |
+ $form['user'] = array( | |
+ '#type' => 'checkbox', | |
+ '#title' => t('Load default filter from user page, that\'s good for related taxonomy blocks'), | |
+ '#default_value' => $this->options['user'], | |
+ ); | |
$form['limit'] = array( | |
'#type' => 'checkbox', | |
@@ -54,6 +60,7 @@ class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_d | |
'#process' => array('form_process_checkbox', 'ctools_dependent_process'), | |
'#dependency' => array( | |
'edit-options-argument-default-taxonomy-tid-node' => array(1), | |
+ 'edit-options-argument-default-taxonomy-tid-user' => array(1), | |
), | |
); | |
@@ -74,6 +81,7 @@ class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_d | |
'#dependency' => array( | |
'edit-options-argument-default-taxonomy-tid-limit' => array(1), | |
'edit-options-argument-default-taxonomy-tid-node' => array(1), | |
+ 'edit-options-argument-default-taxonomy-tid-user' => array(1), | |
), | |
); | |
@@ -88,6 +96,7 @@ class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_d | |
), | |
'#dependency' => array( | |
'edit-options-argument-default-taxonomy-tid-node' => array(1), | |
+ 'edit-options-argument-default-taxonomy-tid-user' => array(1), | |
), | |
); | |
} | |
@@ -144,6 +153,46 @@ class views_plugin_argument_default_taxonomy_tid extends views_plugin_argument_d | |
} | |
} | |
+ // Load default argument from user. | |
+ if (!empty($this->options['user'])) { | |
+ foreach (range(1, 3) as $i) { | |
+ $user = menu_get_object('user', $i); | |
+ if (!empty($user)) { | |
+ break; | |
+ } | |
+ } | |
+ // Just check, if a user could be detected. | |
+ if ($user) { | |
+ $taxonomy = array(); | |
+ $fields = field_info_instances('user', 'user'); | |
+ foreach ($fields as $name => $info) { | |
+ $field_info = field_info_field($name); | |
+ if ($field_info['type'] == 'taxonomy_term_reference') { | |
+ $items = field_get_items('user', $user, $name); | |
+ if (is_array($items)) { | |
+ foreach ($items as $item) { | |
+ $taxonomy[$item['tid']] = $field_info['settings']['allowed_values'][0]['vocabulary']; | |
+ } | |
+ } | |
+ } | |
+ } | |
+ if (!empty($this->options['limit'])) { | |
+ $tids = array(); | |
+ // filter by vocabulary | |
+ foreach ($taxonomy as $tid => $vocab) { | |
+ if (!empty($this->options['vocabularies'][$vocab])) { | |
+ $tids[] = $tid; | |
+ } | |
+ } | |
+ return implode($this->options['anyall'], $tids); | |
+ } | |
+ // Return all tids. | |
+ else { | |
+ return implode($this->options['anyall'], array_keys($taxonomy)); | |
+ } | |
+ } | |
+ } | |
+ | |
// If the current page is a view that takes tid as an argument, | |
// find the tid argument and return it. | |
$views_page = views_get_page_view(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment