You are here

function menu_reference_plugin_argument_default_menu_trail::get_argument in Menu Reference 7

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

views/plugins/menu_reference_plugin_argument_default_menu_trail.inc, line 44
Views plugin for argument default value.

Class

menu_reference_plugin_argument_default_menu_trail
Default argument plugin to return current page menu trail.

Code

function get_argument() {
  $allowed_menu = is_array($this->options['allowed_menu']) ? array_filter($this->options['allowed_menu']) : array();
  $depth = $this->options['depth'];
  $include_front = $this->options['include_front'];
  $current_path = $_GET['q'];
  $menu_links = $this
    ->get_menu_links_by_path($current_path, $allowed_menu);
  $mlids_priority = array();
  foreach ($menu_links as $link) {
    $mlids_priority[0][] = $link->mlid;
    for ($l = $depth; $l > 0; $l--) {
      $key = 'p' . $l;
      if ($link->{$key} > 0 && $link->mlid != $link->{$key}) {
        $mlids_priority[$l][] = $link->{$key};
      }
    }
  }
  if ($include_front) {
    $menu_front_links = $this
      ->get_menu_links_by_path('<front>', $allowed_menu);
    foreach ($menu_front_links as $link) {
      $mlids_priority[99][] = $link->mlid;
    }
  }
  $mlids = array();
  foreach ($mlids_priority as $set) {
    foreach ($set as $item) {
      $mlids[] = $item;
    }
  }
  foreach ($mlids as $key => $value) {
    $result = db_select($this->argument->table)
      ->fields($this->argument->table, array(
      $this->argument->field,
    ))
      ->condition($this->argument->field, $value, '=')
      ->execute()
      ->fetchAssoc();
    if (empty($result[$this->argument->field])) {
      unset($mlids[$key]);
    }
  }
  if (!empty($mlids)) {
    reset($mlids);
    return current($mlids);
  }
  else {
    return NULL;
  }
}