Implement autocomplete UI for the link widget

Created on 1 February 2015, almost 10 years ago
Updated 12 September 2024, 3 months ago

Problem/Motivation

#2416987: Fix UI regression in the menu link form fixed a regression so that the UI was back to a simpler one.

Parts of this are blocked on #2417793: Allow entity: URIs to be entered in link fields

See #2407505: [meta] Finalize the menu links (and other user-entered paths) system and #2407913: Discuss/define the minimal UX for adding menu links to entities for the full backstory.

Basically, in order to ship Drupal 8, we need to restore the ability to form a "smart" link to a piece of content like node/1 that doesn't break even if its path changes, such as from "about" to "about-us." In Drupal 7, this was default behaviour. While we're at it, let's fix a long-standing UX problem due to the fact that normal humans do not know what a "path" is:

Proposed resolution

Based on the decision at #2407913: Discuss/define the minimal UX for adding menu links to entities , implement the UI outlined there. (Note: Exact label/help text hasn't been bike-shedded yet, but we can start on implementation of the behind-the-scenes stuff.)

Behaviour:

  • As user types, autocomplete the input against node titles. (A later improvement in 8.0.x or 8.1.x+ could be expanding this UI to allow for other entity types as well, but that's not in scope for this issue.)
  • If the input has a slash "/" in it, no longer attempt to autocomplete; instead store what the user typed.
  • Code-wise, figure out if what's input is an entity:node/1, a base:README.txt, or a user-path:blog, or just plain http://whatever, and store in the link field's uri field accordingly.

Remaining tasks

  1. Blocker: #2417647: Add leading slash to paths within 'user-path:' URIs, to allow 'user-path:' URIs to point to the route (see #65 for an explanation why)
  2. Review code
  3. Review usability

User interface changes

API changes

📌 Task
Status

Fixed

Version

8.8 ⚰️

Component
Menu system 

Last updated about 1 hour ago

Created by

🇺🇸United States yesct

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany Anybody Porta Westfalica

    Same situation as #129 in a large project. The autocomplete is limited, but doesn't include the result the editors are looking for and the results are not ordered by relevance. So this is an issue on large projects.

    I'm looking for a follow-up issue. If I shouldn't find one and link it here, me or the next who runs into this, should create a follow-up issue for things like:

    • order results by relevancy
    • making the autocomplete limit configurable
    • being able to exclude certain content types, that are irrelevant
    • ...?
  • 🇺🇸United States brooke_heaton

    Does anyone know why the following help text is hard-coded to the link field and seeminly can't be removed?

    Start typing the title of a piece of content to select it. You can also enter an internal path such as %add-node or an external URL such as %url. Enter %front to link to the front page. Enter %nolink to display link text only. Enter %button to display keyboard-accessible link text only.', ['%front' => '', '%add-node' => '/node/add', '%url' => 'http://example.com', '%nolink' => '', '%button' => '']);

    Is there a way to easily remove this text?

Production build 0.71.5 2024