diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-10-24 05:13:44 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-10-24 05:13:44 +0000 |
commit | cd7b8f099996c46a58b354ae262852d222306e74 (patch) | |
tree | 1e7725d67472a1c203ce418f90e2fb48716efd37 /modules/system | |
parent | dec6514c3b2d889c3a9fb19731e49e83d554392c (diff) | |
download | brdo-cd7b8f099996c46a58b354ae262852d222306e74.tar.gz brdo-cd7b8f099996c46a58b354ae262852d222306e74.tar.bz2 |
#320331 by Dave Reid, dww, John Morahan, cwgordon7, moshe weitzman, c960657, and smoothify: Turn custom_url_rewrite_inbound() and custom_url_rewrite_outbound() into hooks.
Diffstat (limited to 'modules/system')
-rw-r--r-- | modules/system/system.api.php | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/modules/system/system.api.php b/modules/system/system.api.php index b379649a6..02c69ee36 100644 --- a/modules/system/system.api.php +++ b/modules/system/system.api.php @@ -2667,5 +2667,61 @@ function hook_page_delivery_callback_alter(&$callback) { } /** + * Alters inbound URL requests. + * + * @param $path + * The path being constructed, which, if a path alias, has been resolved to a + * Drupal path by the database, and which also may have been altered by other + * modules before this one. + * @param $original_path + * The original path, before being checked for path aliases or altered by any + * modules. + * @param $path_language + * The language of the path. + * + * @see drupal_get_normal_path() + */ +function hook_url_inbound_alter(&$path, $original_path, $path_language) { + // Create the path user/me/edit, which allows a user to edit their account. + if (preg_match('|^user/me/edit(/.*)?|', $path, $matches)) { + global $user; + $path = 'user/' . $user->uid . '/edit' . $matches[1]; + } +} + +/** + * Alters outbound URLs. + * + * @param $path + * The outbound path to alter, not adjusted for path aliases yet. It won't be + * adjusted for path aliases until all modules are finished altering it, thus + * being consistent with hook_url_alter_inbound(), which adjusts for all path + * aliases before allowing modules to alter it. This may have been altered by + * other modules before this one. + * @param $options + * A set of URL options for the URL so elements such as a fragment or a query + * string can be added to the URL. + * @param $original_path + * The original path, before being altered by any modules. + * + * @see url() + */ +function hook_url_outbound_alter(&$path, &$options, $original_path) { + // Use an external RSS feed rather than the Drupal one. + if ($path == 'rss.xml') { + $path = 'http://example.com/rss.xml'; + $options['external'] = TRUE; + } + + // Instead of pointing to user/[uid]/edit, point to user/me/edit. + if (preg_match('|^user/([0-9]*)/edit(/.*)?|', $path, $matches)) { + global $user; + if ($user->uid == $matches[1]) { + $path = 'user/me/edit' . $matches[2]; + } + } +} + +/** * @} End of "addtogroup hooks". */ |