Link field > Link display for internal links when no link text is given should not just display node/{node ID}

Created on 15 June 2020, over 4 years ago
Updated 14 June 2024, 5 months ago

Problem/Motivation

Even if no link text is given for internal links, the link display should still be useful. At the moment it just renders /node/123 even if a node has a node title or an alias, and the editors need to copy the link text from the auto complete above ...

Proposed resolution

Add a link field to a node (related links)
Make link text optional
Add an internal like with link text
Add an internal like without link text
Add an external link without link text

Please note: the screenshot is taken form the Sector distribution. So there has been some additional configuration but the issue remains.

Proposed resolution

(Description of the proposed solution, the rationale behind it, and workarounds for people who cannot use the patch.)
In a perfect world the link would be displayed as
1 - node or entity title (if exists ... in almost all cases nodes will have titles
2 - Site domain + node alias (if exists ... even if it is a relative link, the full URL makes it easier to understand for the user)
3 - Site domain + node path (see above)

Remaining tasks

Review and decide on next steps.

Feature request
Status

Needs work

Version

11.0 🔥

Component
Link 

Last updated 1 day ago

Created by

🇳🇿New Zealand heiket

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • 🇺🇸United States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

    Such a feature will require test coverage

  • 🇺🇸United States mpotter

    Patch in #20 works great in D9.5.x. This is super useful and much better than the default behavior.

  • 🇺🇸United States foodslover

    The changes made in Patch #18 & #20 caused an issue where the system attempted to find an entity type called "view_id," which doesn't actually exist in Drupal. This led to an error message: `Drupal\Component\Plugin\Exception\PluginNotFoundException: The "view_id" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition()` when a user accessed the URL `/admin/config/search/redirect`.

    The latest patch has fixed these bugs, ensuring that when using the current version of Drupal 9.5 & 10.1.6, this error no longer occurs when accessing the specified URL.

    This revised code attempts to utilize entity titles for internal URLs. It checks if the provided entity type exists in Drupal before attempting to load an entity. If an entity is loaded successfully, it checks for translations and retrieves the title or name field. For cases where route parameters are absent, it loads links by route and sets the root menu item's title.

    Key modifications:

    1. Check Entity Type Definition: Before attempting to load an entity, hasDefinition() checks if the provided entity type exists in Drupal. This prevents attempting to load non-existent entity types.
    2. Entity Loading and Field Handling: After confirming the existence of the entity type, getStorage() is used to retrieve the entity storage handler.
  • 🇺🇸United States kmonahan

    Using this patch and found an issue where, when the Link formatter is used to display the URL only as plain text, the node title is still displayed instead of the URL. Will take a look and update the patch.

  • First commit to issue fork.
  • Pipeline finished with Failed
    5 months ago
    Total: 180s
    #197083
  • Pipeline finished with Success
    5 months ago
    Total: 542s
    #197099
  • Status changed to Needs review 5 months ago
  • 🇮🇳India manish-31

    Opened an MR.
    Added tests for this change and minor coding standard fixed from patch #36. Needs review.

  • Status changed to Needs work 5 months ago
  • 🇺🇸United States smustgrave

    Issue summary appears to have broken images can those be updated.

    Left small comment on MR.

  • Status changed to Needs review 5 months ago
  • Pipeline finished with Failed
    5 months ago
    Total: 633s
    #197480
  • Status changed to Needs work 5 months ago
  • 🇺🇸United States smustgrave

    Issue summary still needs cleaning up per #40

Production build 0.71.5 2024