diff --git a/core/includes/batch.inc b/core/includes/batch.inc index b9e49f7..0e9dfe1 100644 --- a/core/includes/batch.inc +++ b/core/includes/batch.inc @@ -452,7 +452,8 @@ function _batch_finished() { if ($_batch['form_state']->getRedirect() === NULL) { $redirect = $_batch['batch_redirect'] ?: $_batch['source_url']; $options = UrlHelper::parse($redirect); - if (UrlHelper::isExternal($options['path']) || strpos($options['path'], 'base://') === 0) { + // Any path with a scheme does not correspond to a route. + if (parse_url($options['path'], PHP_URL_SCHEME)) { $redirect = Url::unrouted($options['path'], $options); } else { diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 2fc2d56..d763045 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -543,7 +543,7 @@ function install_run_task($task, &$install_state) { } // Process the batch. For progressive batches, this will redirect. // Otherwise, the batch will complete. - $response = batch_process('base://' . install_redirect_url($install_state), install_full_redirect_url($install_state)); + $response = batch_process(preg_replace('@^core/@', 'base://', install_redirect_url($install_state)), install_full_redirect_url($install_state)); if ($response instanceof Response) { // Save $_SESSION data from batch. \Drupal::service('session_manager')->save(); diff --git a/core/lib/Drupal/Core/Menu/MenuLinkBase.php b/core/lib/Drupal/Core/Menu/MenuLinkBase.php index 6edbcc0..c0f05e0 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkBase.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkBase.php @@ -141,8 +141,7 @@ public function getUrlObject($title_attribute = TRUE) { return new Url($this->pluginDefinition['route_name'], $this->pluginDefinition['route_parameters'], $options); } else { - $url = Url::unrouted($this->pluginDefinition['url'], $options); - return $url; + return Url::unrouted($this->pluginDefinition['url'], $options);; } } diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index bdae691..04a961c 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -254,7 +254,7 @@ public function isRouted() { * @return string * * @throws \UnexpectedValueException. - * If this is an URI with no corresponding route. + * If this is a URI with no corresponding route. */ public function getRouteName() { if ($this->unrouted) { @@ -270,7 +270,7 @@ public function getRouteName() { * @return array * * @throws \UnexpectedValueException. - * If this is an URI with no corresponding route. + * If this is a URI with no corresponding route. */ public function getRouteParameters() { if ($this->unrouted) { @@ -289,7 +289,7 @@ public function getRouteParameters() { * @return $this * * @throws \UnexpectedValueException. - * If this is an URI with no corresponding route. + * If this is a URI with no corresponding route. */ public function setRouteParameters($parameters) { if ($this->unrouted) { @@ -310,7 +310,7 @@ public function setRouteParameters($parameters) { * @return $this * * @throws \UnexpectedValueException. - * If this is an URI with no corresponding route. + * If this is a URI with no corresponding route. */ public function setRouteParameter($key, $value) { if ($this->unrouted) { @@ -471,7 +471,7 @@ public function toRenderArray() { * The internal path for this route. * * @throws \UnexpectedValueException. - * If this is an URI with no corresponding system path. + * If this is a URI with no corresponding system path. * * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. * System paths should not be used - use route names and parameters. diff --git a/core/lib/Drupal/Core/Utility/UnroutedUrlAssemblerInterface.php b/core/lib/Drupal/Core/Utility/UnroutedUrlAssemblerInterface.php index cba87fe..36fca11 100644 --- a/core/lib/Drupal/Core/Utility/UnroutedUrlAssemblerInterface.php +++ b/core/lib/Drupal/Core/Utility/UnroutedUrlAssemblerInterface.php @@ -12,23 +12,24 @@ interface UnroutedUrlAssemblerInterface { /** - * Builds a domain-local or external URL from a path or URL. + * Builds a domain-local or external URL from a URI. * * For actual implementations the logic probably has to be split up between - * domain-local and external URLs. + * domain-local URIs and external URLs. * * @param string $uri - * A path on the same domain or external URL being linked to, such as "foo" + * A local URI or an external URL being linked to, such as "base://foo" * or "http://example.com/foo". * - If you provide a full URL, it will be considered an external URL as * long as it has an allowed protocol. - * - If you provide only a path (e.g. "foo"), it will be - * considered a URL local to the same domain. Additional query - * arguments for local paths must be supplied in $options['query'], not - * included in $path. + * - If you provide only a local URI (e.g. "base://foo"), it will be + * considered a path local to Drupal, but not handled by the routing + * system. The base path (the subdirectory where the front controller + * is found) will be added to the path. Additional query arguments for + * local paths must be supplied in $options['query'], not part of $uri. * - If your external URL contains a query (e.g. http://example.com/foo?a=b), * then you can either URL encode the query keys and values yourself and - * include them in $path, or use $options['query'] to let this method + * include them in $uri, or use $options['query'] to let this method * URL encode them. * * @param array $options diff --git a/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php b/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php index 65e37bf..2d9cc98 100644 --- a/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php +++ b/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php @@ -207,22 +207,7 @@ protected function buildUrl(LinkItemInterface $item) { } if ($item->isExternal()) { - // @todo LinkItemInterface shouldn't treat items with no scheme as - // external, including . All the code here should be removed - // except the first case where we have a valid scheme. There needs to - // be some fixes in RDF module since changing this causes failures in - // Drupal\rdf\Tests\Field\LinkFieldRdfaTest - // https://www.drupal.org/node/2346645 - if (parse_url($item->url, PHP_URL_SCHEME)) { - $url = Url::unrouted($item->url, $options); - } - elseif ($item->url == '') { - $url = new Url(''); - } - else { - // No base path - assume internal. - $url = Url::createFromRequest(Request::create('/' . ltrim($item->url, '/'))); - } + $url = Url::unrouted($item->url, $options); } else { $url = Url::routed($item->route_name, (array) $item->route_parameters, (array) $options); diff --git a/core/modules/rdf/src/Tests/Field/LinkFieldRdfaTest.php b/core/modules/rdf/src/Tests/Field/LinkFieldRdfaTest.php index 8c23c07..8478bae 100644 --- a/core/modules/rdf/src/Tests/Field/LinkFieldRdfaTest.php +++ b/core/modules/rdf/src/Tests/Field/LinkFieldRdfaTest.php @@ -75,7 +75,8 @@ public function testAllFormattersInternal() { // Set up test values. $this->testValue = 'admin'; $this->entity = entity_create('entity_test', array()); - $this->entity->{$this->fieldName}->url = $this->testValue; + $this->entity->{$this->fieldName}->route_name = 'system.admin'; + $this->entity->{$this->fieldName}->url = 'admin'; // Set up the expected result. // AssertFormatterRdfa looks for a full path. @@ -94,7 +95,8 @@ public function testAllFormattersFront() { // Set up test values. $this->testValue = ''; $this->entity = entity_create('entity_test', array()); - $this->entity->{$this->fieldName}->url = $this->testValue; + $this->entity->{$this->fieldName}->route_name = $this->testValue; + $this->entity->{$this->fieldName}->url = ''; // Set up the expected result. $expected_rdf = array( diff --git a/core/modules/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php index 4c331f7..4bd041e 100644 --- a/core/modules/shortcut/src/Entity/Shortcut.php +++ b/core/modules/shortcut/src/Entity/Shortcut.php @@ -135,6 +135,9 @@ public static function preCreate(EntityStorageInterface $storage, array &$values public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); + // @todo fix PathValidatorInterface::getUrlIfValid() so we can use it + // here. The problem is that we need an exception, not a FALSE + // return value. https://www.drupal.org/node/2346695 if ($this->path->value == '') { $url = new Url($this->path->value); } diff --git a/core/modules/update/update.report.inc b/core/modules/update/update.report.inc index e885ce5..b5215e2 100644 --- a/core/modules/update/update.report.inc +++ b/core/modules/update/update.report.inc @@ -6,6 +6,7 @@ */ use Drupal\Core\Template\Attribute; +use Drupal\Core\Url; /** * Prepares variables for project status report templates. @@ -135,7 +136,7 @@ function template_preprocess_update_project_status(&$variables) { // Set the project title and URL. $variables['title'] = (isset($project['title'])) ? $project['title'] : $project['name']; - $variables['url'] = (isset($project['link'])) ? \Drupal::service('unrouted_url_assembler')->assemble($project['link']) : NULL; + $variables['url'] = (isset($project['link'])) ? Url::unrouted($project['link'])->toString() : NULL; $variables['install_type'] = $project['install_type']; if ($project['install_type'] == 'dev' && !empty($project['datestamp'])) { diff --git a/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php b/core/tests/Drupal/Tests/Core/ExternalUrlTest.php similarity index 100% rename from core/tests/Drupal/Tests/Core/UnroutedUrlTest.php rename to core/tests/Drupal/Tests/Core/ExternalUrlTest.php