core/misc/autocomplete.js | 1 - .../src/Plugin/Field/FieldWidget/LinkWidget.php | 36 +++++++++++++--------- .../system/src/Tests/Menu/BreadcrumbTest.php | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/core/misc/autocomplete.js b/core/misc/autocomplete.js index d9f230d..b4e4123 100644 --- a/core/misc/autocomplete.js +++ b/core/misc/autocomplete.js @@ -62,7 +62,6 @@ var options = autocomplete.options; var term = autocomplete.extractLastTerm(event.target.value); // Abort search if the first character is in firstCharacterBlacklist. - debugger; if (term.length > 0 && options.firstCharacterBlacklist.indexOf(term[0]) !== -1) { return false; } diff --git a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php index 24a6237..486db63 100644 --- a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php @@ -44,7 +44,11 @@ public static function defaultSettings() { } /** - * Gets the URI without the 'user-path:' scheme, for display while editing. + * Gets the URI without the 'user-path:' or 'entity:' scheme. + * + * The following two forms of URIs are transformed: + * - 'entity:' URIs: to entity autocomplete ("label (entity id)") strings; + * - 'user-path:' URIs: the scheme is stripped. * * This method is the inverse of ::getUserEnteredStringAsUri(). * @@ -94,7 +98,9 @@ protected static function getUriAsDisplayableString($uri) { /** * Gets the user-entered string as a URI. * - * Schemeless URIs are treated as 'user-path:' URIs. + * The following two forms of input are mapped to URIs: + * - entity autocomplete ("label (entity id)") strings: to 'entity:' URIs; + * - strings without a detectable scheme: to 'user-path:' URIs. * * This method is the inverse of ::getUriAsDisplayableString(). * @@ -107,22 +113,24 @@ protected static function getUriAsDisplayableString($uri) { * @see getUriAsDisplayableString() */ protected static function getUserEnteredStringAsUri($string) { + // By default, assume the entered string is an URI. + $uri = $string; + + // Detect entity autocomplete string, map to 'entity:' URI. $entity_id = EntityAutocomplete::extractEntityIdFromAutocompleteInput($string); if ($entity_id !== NULL) { - $string = 'entity:node/' . $entity_id; + // @todo Support entity types other than 'node'. + $uri = 'entity:node/' . $entity_id; } - - if (!empty($string)) { - // Users can enter relative URLs, but we need a valid URI, so add an - // explicit scheme when necessary. - if (parse_url($string, PHP_URL_SCHEME) === NULL) { - // @todo The ltrim() call here will become obsolete as soon as - // https://www.drupal.org/node/241764 lands; see earlier todo for - // more info. - $string = 'user-path:' . ltrim($string, '/'); - } + // Detect a schemeless string, map to 'user-path:' URI. + elseif (!empty($string) && parse_url($string, PHP_URL_SCHEME) === NULL) { + // @todo The ltrim() call here will become obsolete as soon as + // https://www.drupal.org/node/241764 lands; see earlier todo for + // more info. + $uri = 'user-path:' . ltrim($string, '/'); } - return $string; + + return $uri; } /** diff --git a/core/modules/system/src/Tests/Menu/BreadcrumbTest.php b/core/modules/system/src/Tests/Menu/BreadcrumbTest.php index 1755091..3048e37 100644 --- a/core/modules/system/src/Tests/Menu/BreadcrumbTest.php +++ b/core/modules/system/src/Tests/Menu/BreadcrumbTest.php @@ -248,7 +248,7 @@ function testBreadCrumbs() { $menu_links = entity_load_multiple_by_properties('menu_link_content', array( 'title' => $edit['title[0][value]'], // @todo Use link.uri once https://www.drupal.org/node/2391217 is in. - 'link__uri' => 'user-path:/taxonomy/term/' . $term->id(), + 'link__uri' => 'user-path:taxonomy/term/' . $term->id(), )); $tags[$name]['link'] = reset($menu_links); $parent_mlid = $tags[$name]['link']->getPluginId();