diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index 9ea38b2..0703413 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -203,7 +203,7 @@ public static function fromRoute($route_name, $route_parameters = array(), $opti * @see static::fromRoute() */ public static function fromUri($uri, $options = array()) { - if (!parse_url($uri, PHP_URL_SCHEME)) { + if ($uri != 'base://' && !parse_url($uri, PHP_URL_SCHEME)) { throw new \InvalidArgumentException(String::format('The URI "@uri" is invalid. You must use a valid URI scheme. Use base:// for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal.', ['@uri' => $uri])); } diff --git a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php index 802c0ab..112231a 100644 --- a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php @@ -7,6 +7,7 @@ namespace Drupal\link\Plugin\Field\FieldWidget; +use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\WidgetBase; @@ -47,7 +48,8 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen if (isset($items[$delta]->url)) { if ($url = \Drupal::pathValidator()->getUrlIfValid($items[$delta]->url)) { $url->setOptions($items[$delta]->options); - $default_url_value = ltrim($url->toString(), '/'); + $url_string = $url->toString(); + $default_url_value = $url->isRouted() ? Unicode::substr($url_string, strlen(base_path())) : $url_string; } } $element['url'] = array( diff --git a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php index fb484eb..1d9d047 100644 --- a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php @@ -8,6 +8,7 @@ namespace Drupal\shortcut\Tests; use Drupal\Component\Utility\String; +use Drupal\Core\Url; use Drupal\shortcut\Entity\Shortcut; use Drupal\shortcut\Entity\ShortcutSet; @@ -61,7 +62,7 @@ public function testShortcutLinkAdd() { $saved_set = ShortcutSet::load($set->id()); $paths = $this->getShortcutInformation($saved_set, 'link'); $test['path'] = $test['path'] != '' ? $test['path'] : ''; - $this->assertTrue(in_array($test['path'], $paths), 'Shortcut created: ' . $test['path']); + $this->assertTrue(in_array(Url::fromUri('base://' . $test['path']), $paths), 'Shortcut created: ' . $test['path']); $this->assertLink($title, 0, String::format('Shortcut link %url found on the page.', ['%url' => $test['path']])); } $saved_set = ShortcutSet::load($set->id()); @@ -87,7 +88,7 @@ public function testShortcutLinkAdd() { ]; $this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $set->id() . '/add-link', $form_data, t('Save')); $this->assertResponse(200); - $this->assertRaw(t('The URL admin is not valid.')); + $this->assertRaw(String::format('The URL %url is not valid.', ['%url' => 'admin'])); $form_data = [ 'title[0][value]' => $title, @@ -159,7 +160,7 @@ public function ptestShortcutLinkChangePath() { $this->drupalPostForm('admin/config/user-interface/shortcut/link/' . $shortcut->id(), array('title[0][value]' => $shortcut->getTitle(), 'link[0][url]' => $new_link_path), t('Save')); $saved_set = ShortcutSet::load($set->id()); $paths = $this->getShortcutInformation($saved_set, 'link'); - $this->assertTrue(in_array($new_link_path, $paths), 'Shortcut path changed: ' . $new_link_path); + $this->assertTrue(in_array(Url::fromUri('base://' . $new_link_path), $paths), 'Shortcut path changed: ' . $new_link_path); $this->assertLinkByHref($new_link_path, 0, 'Shortcut with new path appears on the page.'); } diff --git a/core/modules/shortcut/src/Tests/ShortcutTestBase.php b/core/modules/shortcut/src/Tests/ShortcutTestBase.php index 4126b99..34abfe2 100644 --- a/core/modules/shortcut/src/Tests/ShortcutTestBase.php +++ b/core/modules/shortcut/src/Tests/ShortcutTestBase.php @@ -122,7 +122,7 @@ function getShortcutInformation(ShortcutSetInterface $set, $key) { \Drupal::entityManager()->getStorage('shortcut')->resetCache(); foreach ($set->getShortcuts() as $shortcut) { if ($key == 'link') { - $info[] = ltrim($shortcut->getUrl()->toString(), '/'); + $info[] = $shortcut->getUrl()->toString(); } else { $info[] = $shortcut->{$key}->value;