Add a basic matcher for anchors

Created on 19 April 2021, over 3 years ago
Updated 12 September 2023, about 1 year ago

Problem/Motivation

When people add links to anchors on the same page, they get the message that Linkit could not find any suggestions. This is confusing some users, leading them to believe the anchor won't work at all.

Steps to reproduce

Add a link to an anchor, like "#example", and note that Linkit says it can't find suggestions.

Proposed resolution

Create a basic matcher for anchors that just takes anything that starts with "#" and tells people that it is an anchor.

A more advanced version of this could check within the current CKeditor window, but that might actually be more confusing for people as potentially there are other anchors on the published page that didn't come from the same CKeditor window (e.g. a page built with a lot of layout builder blocks).

Remaining tasks

A patch adding a basic anchor matcher, and a test for the same, is coming shortly. It's based off how the email matcher works.

User interface changes

This adds an optional "Anchor (basic)" matcher to the list of available matchers.

API changes

None.

Data model changes

None.

✨ Feature request
Status

RTBC

Version

5.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada kpaxman

Live updates comments and jobs are added and updated live.
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.

  • πŸ‡§πŸ‡ͺBelgium kriboogh

    Tested and works +1
    Been 2 years, what is holding us back to get this in ?

  • Status changed to Needs review about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Been 2 years, what is holding us back to get this in ?

    Thanks for checking in on this. The previous maintainers of this module moved on to other things; I have taken over active maintainership since April 2023, and have been making my way through the backlog of nearly 200 issues. Since there had been no activity on this issue in 2 years, I hadn't yet seen it.

    In principle I agree with the goal of this basic matcher: "Create a basic matcher for anchors that just takes anything that starts with "#" and tells people that it is an anchor."

    This will need to be tested against the 6.x branch; active development is no longer happening in 8.x-5.x. I'll set the version number to 6.1.x and set it back to "Needs review." If someone can functionally test it against the 6.1.x branch and demonstrate that the automated test suite passes, that would be great.

  • First commit to issue fork.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    47 pass, 2 fail
  • Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    Not currently mergeable.
  • @sleitner opened merge request.
  • Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    Not currently mergeable.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    84 pass
  • Status changed to RTBC about 1 year ago
  • πŸ‡©πŸ‡ͺGermany sleitner

    Tested and works fine.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Tested patch #10 and doesn't appear to be working for us. Doesn't do a search.

  • πŸ‡¨πŸ‡¦Canada kpaxman

    As noted, this is just a basic matcher. It doesn't try to search existing anchors, it just assumes anything that starts with # is an anchor.

    It could probably be extended to search anchors within an existing editor block, but I'm not sure how this would work in a field or in a layout builder environment when you have multiple blocks on a page, each potentially with anchors, not necessarily served by an editor.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    So what's the difference with ✨ Add better support for linking to anchors Postponed: needs info

  • πŸ‡¨πŸ‡¦Canada kpaxman

    While noting that it's been years since I wrote this, at a glance I would say the difference is that this tackles the first bullet point from that other ticket, which from what I can tell the other one makes no attempt to solve. This patch makes no effort to solve the other bullet point, which *does* seem to be getting solved in the other ticket.

  • Status changed to Needs work about 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States byronveale

    Tested the patch from #10 with Linkit 6.1.4 and found no difference in Linkit’s behavior. Instead of seeing the added β€œLinks to an anchor named @anchor on the current page” message, saw the current β€œNo content suggestions found. This URL will be used as is.” message.

  • πŸ‡ΊπŸ‡ΈUnited States byronveale

    Enabled Xdebug, added a breakpoint to the added AnchorMatcher plugin, found that it was ignored when adding an anchor link (starting with β€œ#”).

    As a comparison test, added a breakpoint to the EmailMatcher plugin, which was not ignored when adding an email link.

    Comparing the two plugins, I could not find any obvious reason why the AnchorMatcher would be ignored.

  • πŸ‡ΊπŸ‡ΈUnited States byronveale

    One last note, FWIW I also tried the patch with 7.0.0-alpha1, same results.

Production build 0.71.5 2024