function current_path

Return the current URL path of the page being viewed.

Examples:

This function is not available in hook_boot() so use request_path() instead. However, be careful when doing that because in the case of Example #3 request_path() will contain "path/alias". If "node/306" is needed, calling drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL) makes this function available.

Return value

The current Drupal URL path.

See also

request_path()

47 calls to current_path()
batch_process in drupal/core/includes/form.inc
Processes the batch.
block_block_list_alter in drupal/core/modules/block/block.module
Implements hook_block_list_alter().
common_test_l_active_class in drupal/core/modules/system/tests/modules/common_test/common_test.module
Page callback: Displays links to the current page, one with a query string.
contact_mail in drupal/core/modules/contact/contact.module
Implements hook_mail().
drupal_add_js in drupal/core/includes/common.inc
Adds a JavaScript file, setting, or inline code to the page.

... See full list

File

drupal/core/includes/path.inc, line 86
Functions to handle paths in Drupal.

Code

function current_path() {

  // @todo Remove the check for whether the request service exists and the
  // fallback code below, once the path alias logic has been figured out in
  // http://drupal.org/node/1269742.
  if (drupal_container()
    ->isScopeActive('request')) {
    return drupal_container()
      ->get('request')->attributes
      ->get('system_path');
  }

  // If we are outside the request scope, fall back to using the path stored in
  // _current_path().
  return _current_path();
}