1 redirect.module redirect_url($path, array $options = array(), $clean_url = NULL)

Build the URL of a redirect for display purposes only.

Parameters

string $path: The internal Backdrop path to be displayed.

array $options: An array of options as would be passed into the url() function.

bool|NULL $clean_url: Whether the returns string should use clean URLs or not. Defaults to the site-wide setting for clean URLs.

Return value

string: A string suitable for display. Note this is not yet escaped for HTML, so check_plain() should still be used if printing to HTML.

File

core/modules/redirect/redirect.module, line 1113

Code

function redirect_url($path, array $options = array(), $clean_url = NULL) {
  if (!isset($clean_url)) {
    $clean_url = config_get('system.core', 'clean_url');
  }

  if ($path == '') {
    $path = '<front>';
  }

  if (!isset($options['alter']) || !empty($options['alter'])) {
    backdrop_alter('redirect_url', $path, $options);
  }

  // The base_url might be rewritten from the language rewrite in domain mode.
  if (!isset($options['base_url'])) {
    if (isset($options['https']) && settings_get('https', FALSE)) {
      if ($options['https'] === TRUE) {
        $options['base_url'] = $GLOBALS['base_secure_url'];
        $options['absolute'] = TRUE;
      }
      elseif ($options['https'] === FALSE) {
        $options['base_url'] = $GLOBALS['base_insecure_url'];
        $options['absolute'] = TRUE;
      }
    }
    else {
      $options['base_url'] = $GLOBALS['base_url'];
    }
  }

  if (empty($options['absolute']) || url_is_external($path)) {
    $url = $path;
  }
  else {
    $url = $options['base_url'] . base_path() . $path;
  }

  if (isset($options['query'])) {
    $url .= $clean_url ? '?' : '&';
    $url .= backdrop_http_build_query($options['query']);
  }
  if (isset($options['fragment'])) {
    $url .= '#' . $options['fragment'];
  }

  return $url;
}