You are here

function view::get_url in Views (for Drupal 7) 6.2

Same name and namespace in other branches
  1. 6.3 includes/view.inc \view::get_url()
  2. 7.3 includes/view.inc \view::get_url()

Get the URL for the current view.

This URL will be adjusted for arguments.

1 call to view::get_url()
view::_build_arguments in includes/view.inc
Build all the arguments.

File

includes/view.inc, line 1168
view.inc Provides the view object type and associated methods.

Class

view
An object to contain all of the data to generate a view, plus the member functions to build the view query, execute the query and render the output.

Code

function get_url($args = NULL, $path = NULL) {
  if (!isset($path)) {
    $path = $this
      ->get_path();
  }
  if (!isset($args)) {
    $args = $this->args;
  }

  // Don't bother working if there's nothing to do:
  if (empty($path) || empty($args) && strpos($path, '%') === FALSE) {
    return $path;
  }
  $pieces = array();
  $arguments = isset($arguments) ? $arguments : $this->display_handler
    ->get_option('arguments');
  $argument_keys = isset($arguments) ? array_keys($arguments) : array();
  $id = current($argument_keys);
  foreach (explode('/', $path) as $piece) {
    if ($piece != '%') {
      $pieces[] = $piece;
    }
    else {
      if (empty($args)) {

        // Try to never put % in a url; use the wildcard instead.
        if ($id && !empty($arguments[$id]['wildcard'])) {
          $pieces[] = $arguments[$id]['wildcard'];
        }
        else {
          $pieces[] = '*';

          // gotta put something if there just isn't one.
        }
      }
      else {
        $pieces[] = array_shift($args);
      }
      if ($id) {
        $id = next($argument_keys);
      }
    }
  }
  if (!empty($args)) {
    $pieces = array_merge($pieces, $args);
  }
  return implode('/', $pieces);
}