1 views_plugin_argument_default_taxonomy_tid.inc | views_plugin_argument_default_taxonomy_tid::get_argument() |
Return the default argument.
This needs to be overridden by every default argument handler to properly do what is needed.
Overrides views_plugin_argument_default::get_argument
File
- core/
modules/ taxonomy/ views/ views_plugin_argument_default_taxonomy_tid.inc, line 100 - Definition of views_plugin_argument_default_taxonomy_tid.
Class
- views_plugin_argument_default_taxonomy_tid
- Taxonomy tid default argument.
Code
function get_argument() {
// Load default argument from taxonomy page.
if (!empty($this->options['term_page'])) {
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
return arg(2);
}
}
// Load default argument from node.
if (!empty($this->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) {
$taxonomy = array();
$fields = field_info_instances('node', $node->type);
foreach ($fields as $name => $info) {
$field_info = field_info_field($name);
if ($field_info['type'] == 'taxonomy_term_reference') {
$items = field_get_items('node', $node, $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();
if ($views_page && isset($views_page->argument['tid'])) {
return $views_page->argument['tid']->argument;
}
}