diff --git a/core/includes/common.inc b/core/includes/common.inc index fde8b0683a1..3b6f1ddeb59 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -642,21 +642,7 @@ function _format_date_callback(array $matches = NULL, $new_langcode = NULL) { * @see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromPath(). */ 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; + return \Drupal::urlGenerator()->generateFromPath($path, $options); } /** diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 3d5a2ad16ff..0c01ee8b1c5 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -886,6 +886,9 @@ function install_display_output($output, $install_state) { // reached in case of an early installer error. drupal_maintenance_theme(); + // Ensure the URL generator is initialized. + \Drupal::urlGenerator()->updateFromRequest(); + drupal_page_header(); // Prevent install.php from being indexed when installed in a sub folder. diff --git a/core/lib/Drupal/Core/Routing/NullGenerator.php b/core/lib/Drupal/Core/Routing/NullGenerator.php index 1430f1f744d..2c6597a6121 100644 --- a/core/lib/Drupal/Core/Routing/NullGenerator.php +++ b/core/lib/Drupal/Core/Routing/NullGenerator.php @@ -22,6 +22,16 @@ class NullGenerator extends UrlGenerator { public function __construct() { } + /** + * {@inheritdoc} + */ + public function updateFromRequest() { + global $base_url, $base_path, $script_path; + $this->basePath = $base_path; + $this->baseUrl = $base_url . '/'; + $this->scriptPath = $script_path; + } + /** * {@inheritdoc} *