You are here

function purl_url_outbound_alter in Persistent URL 6

Same name and namespace in other branches
  1. 7 purl.module \purl_url_outbound_alter()

Implementation of hook_url_outbound_alter().

Rewrites path with the current modifier and removes the modifier if searching for source path.

purl extends the $options array in four ways:

#1 If $options['purl']['disabled'] is true none of the detected and removed path modifications will be re-instated. This allows you to drop all purl modifications

#2 $options['purl']['remove'] can be set to an array of providers which Should be dropped, while others are maintained. Setting this when $options['purl']['disabled'] is true is redundant.

#3 $options['purl']['provider'] and $options['purl']['id'] can be used together to set a specific modification to the link.

#4 $options['purl]['add'] can be used to add a set of id's and provider's to the link.

1 call to purl_url_outbound_alter()
purl.module in ./purl.module

File

./purl.module, line 316

Code

function purl_url_outbound_alter(&$path, &$options, $original) {
  static $global_elements;

  // Check to see whether url rewriting has been disabled or isn't
  // suitable for this path.
  if (!purl_disable() && empty($options['alias']) && !strpos($path, '://')) {
    $elements = array();
    if (!isset($global_elements)) {
      $global_elements = array();

      // Retrieve the path values for the current page that were
      // "stripped out" and write them back into url paths.
      foreach (purl_active()
        ->get() as $method => $items) {

        // Array_pop instead of iterating to preseve order.
        while ($item = array_pop($items)) {
          $global_elements[$item->provider] = $item;
        }
      }
    }
    $elements = $global_elements;

    // The current url has requested a specific PURL modifier add it.
    if (!empty($options['purl']['provider']) && !empty($options['purl']['id'])) {
      if ($e = purl_generate_rewrite_elements($options['purl'])) {
        $elements = array(
          $e,
        );
      }
    }
    elseif (isset($options['purl']['add'])) {
      foreach ($options['purl']['add'] as $item) {
        if ($e = purl_generate_rewrite_elements($item)) {
          $elements[$item['provider']] = $e;
        }
      }
    }
    foreach ($elements as $e) {
      $e->processor
        ->rewrite($path, $options, $e);
    }
  }
}