function url

Generates an internal or external URL.

When creating links in modules, consider whether l() could be a better alternative than url().

See also

\Drupal\Core\Routing\PathBasedGeneratorInterface::generateFromPath().

315 calls to url()
AccountFormController::validate in drupal/core/modules/user/lib/Drupal/user/AccountFormController.php
Overrides Drupal\Core\Entity\EntityFormController::submit().
AccountSettingsForm::buildForm in drupal/core/modules/user/lib/Drupal/user/AccountSettingsForm.php
Implements \Drupal\Core\Form\FormInterface::buildForm().
action_help in drupal/core/modules/action/action.module
Implements hook_help().
AddFeedTest::testAddFeed in drupal/core/modules/aggregator/lib/Drupal/aggregator/Tests/AddFeedTest.php
Creates and ensures that a feed is unique, checks source, and deletes feed.
AddFeedTest::testBasicFeedAddNoTitle in drupal/core/modules/system/lib/Drupal/system/Tests/Common/AddFeedTest.php
Tests drupal_add_feed() with paths, URLs, and titles.

... See full list

26 string references to 'url'
aggregator_schema in drupal/core/modules/aggregator/aggregator.install
Implements hook_schema().
comment_tokens in drupal/core/modules/comment/comment.tokens.inc
Implements hook_tokens().
comment_views_data in drupal/core/modules/comment/comment.views.inc
Implements hook_views_data().
ElementTest::testPlaceHolderText in drupal/core/modules/system/lib/Drupal/system/Tests/Form/ElementTest.php
Tests placeholder text for elements that support placeholders.
FeedFormController::validate in drupal/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php
Overrides Drupal\Core\Entity\EntityFormController::validate().

... See full list

File

drupal/core/includes/common.inc, line 1371
Common functions that many Drupal modules will need to reference.

Code

function url($path = NULL, array $options = array()) {
  $generator = Drupal::urlGenerator();
  try {
    $url = $generator
      ->generateFromPath($path, $options);
  } catch (GeneratorNotInitializedException $e) {

    // Fallback to using globals.
    // @todo Remove this once there is no code that calls url() when there is
    //   no request.
    global $base_url, $base_path, $script_path;
    $generator
      ->setBasePath($base_path);
    $generator
      ->setBaseUrl($base_url . '/');
    $generator
      ->setScriptPath($script_path);
    $url = $generator
      ->generateFromPath($path, $options);
  }
  return $url;
}