You are here

function SubPathautoUnitTestCase::getPathAlias in Sub-pathauto (Sub-path URL Aliases) 7

1 call to SubPathautoUnitTestCase::getPathAlias()
SubPathautoUnitTestCase::assertAlias in ./subpathauto.test

File

./subpathauto.test, line 62
Test integration for the subpathauto.module.

Class

SubPathautoUnitTestCase
@file Test integration for the subpathauto.module.

Code

function getPathAlias($path, $options = array()) {

  // Merge in defaults.
  $options += array(
    'fragment' => '',
    'query' => array(),
    'absolute' => FALSE,
    'alias' => FALSE,
    'prefix' => '',
  );
  if (!isset($options['external'])) {

    // Return an external link if $path contains an allowed absolute URL. Only
    // call the slow drupal_strip_dangerous_protocols() if $path contains a ':'
    // before any / ? or #. Note: we could use url_is_external($path) here, but
    // that would require another function call, and performance inside url() is
    // critical.
    $colonpos = strpos($path, ':');
    $options['external'] = $colonpos !== FALSE && !preg_match('![/?#]!', substr($path, 0, $colonpos)) && drupal_strip_dangerous_protocols($path) == $path;
  }

  // Preserve the original path before altering or aliasing.
  $original_path = $path;

  // Allow other modules to alter the outbound URL and options.
  drupal_alter('url_outbound', $path, $options, $original_path);
  if (isset($options['fragment']) && $options['fragment'] !== '') {
    $options['fragment'] = '#' . $options['fragment'];
  }
  if ($options['external']) {
    return $path;
  }
  global $base_url, $base_secure_url, $base_insecure_url;

  // The special path '<front>' links to the default front page.
  if ($path == '<front>') {
    $path = '';
  }
  elseif (!empty($path) && !$options['alias']) {
    $language = isset($options['language']) && isset($options['language']->language) ? $options['language']->language : '';
    $alias = drupal_get_path_alias($original_path, $language);
    if ($alias != $original_path) {
      $path = $alias;
    }
  }
  return $path;
}