You are here

function views_plugin_argument_default_taxonomy_tid::get_argument in Views (for Drupal 7) 6.2

Same name and namespace in other branches
  1. 6.3 modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc \views_plugin_argument_default_taxonomy_tid::get_argument()
  2. 7.3 modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc \views_plugin_argument_default_taxonomy_tid::get_argument()

Return the default argument.

Overrides views_plugin_argument_default::get_argument

File

modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc, line 82
Taxonomy tid default argument.

Class

views_plugin_argument_default_taxonomy_tid
@file Taxonomy tid default argument.

Code

function get_argument() {

  // Load default argument from taxonomy page.
  if (!empty($this->argument->options[$this->option_name . '_term_page'])) {
    if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
      return arg(2);
    }
  }

  // Load default argument from node.
  if (!empty($this->argument->options[$this->option_name . '_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[$this->option_name . '_limit'])) {
        $tids = array();

        // Filter by vid.
        foreach ($node->taxonomy as $tid => $term) {
          if (!empty($this->argument->options[$this->option_name . '_vids'][$term->vid])) {
            $tids[] = $tid;
          }
        }
        return implode(",", $tids);
      }
      else {
        return implode(",", array_keys($node->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->view->argument['tid'])) {
    return $views_page->view->argument['tid']->argument;
  }
}