You are here

function context_prefix_url_rewrite in Context 5

Rewrites path with current context and removes context if searching for source path

1 call to context_prefix_url_rewrite()
cl in context_prefix/context_prefix.module
Custom l wrapper for links that need to leave all group contexts

File

context_prefix/context_prefix.module, line 112

Code

function context_prefix_url_rewrite($type, $path, $original) {
  $working_path = $path;

  // preserve original path
  $args = array();

  // Check to see whether url rewriting has been disabled for this one
  // instance -- currently only possible through cl()
  if (!clswitch('get')) {
    $active_path_prefixes = array();

    // Retrieve the path prefixes for the current page that were
    // "stripped out" and write them back into url paths.
    foreach (context_prefix_get(CONTEXT_PREFIX_PAIR) as $item) {
      $active_path_prefixes[] = $item['prefix'] . '/' . $item['id'];
    }
    foreach (context_prefix_get(CONTEXT_PREFIX_PATH) as $item) {
      $active_path_prefixes[] = $item['prefix'];
    }
    if (count($active_path_prefixes)) {
      $parsed = context_prefix_parse(CONTEXT_PREFIX_PATH, $working_path) + context_prefix_parse(CONTEXT_PREFIX_PAIR, $working_path);

      // A "normal" url was requested -- prefix the path
      if (!$options['alias'] && !strpos($path, '://') && !count($parsed) && count($active_path_prefixes)) {
        $args = $args + $active_path_prefixes;
      }
    }
  }
  if ($working_path) {
    $args[] = $working_path;
  }
  return is_array($args) ? implode('/', $args) : '';
}