Views "Link to URI" formatter fails on trim

Created on 15 August 2024, 5 months ago

Problem/Motivation

The URL formater Link to URI seems to fail with views TRIM feature.

If you add an URL to a view it can be quite long and may move outside of the viewport of you browser. In D7 it was possible to trim l(_filter_url_trim($link->url, 40), $link->url), a link by code. As views have the same feature, I think it should work the same way.

Steps to reproduce

Output an URL (you may use linkchecker module and see the broken links report)
Change the view and set the url field to
"Trim this field to a maximum number of characters" = 40
"Trim only on a word boundary" - disable
Save and you only see "..." (3 dots) as URL that are also not clickable

Proposed resolution

Allow trimming of URLs like l(_filter_url_trim($link->url, 40), $link->url), has done.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

10.3

Component
Views 

Last updated 21 minutes ago

Created by

🇩🇪Germany marc.bau

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @marc.bau
  • 🇮🇳India vinmayiswamy

    Hi, I’ve reproduced the issue with the Link to URI formatter in Drupal 10.3.2. I configured a view to trim URLs to 40 characters, which results in URLs being truncated to "..." and becoming non-clickable.

    In my investigation, I added debug statements and found that while URL truncation works correctly, the HTML generated by the formatter is incorrect. Specifically, the link HTML element is not rendered as a clickable link after truncation. This suggests that the truncation is impacting the HTML anchor tag generation.

    The proposed resolution to use l(_filter_url_trim($link->url, 40), $link->url) seems to be a good approach to address this issue. I will look into applying this method to see if it resolves the problem.

    I did not use the linkchecker module because it is throwing a deprecation error, which prevents me from checking broken links. The module's installed version is 2.0.0, and the error message is:
    Deprecated function: Creation of dynamic property Drupal\linkchecker\Form\LinkCheckerAdminSettingsForm::$moduleHandler is deprecated in Drupal\linkchecker\Form\LinkCheckerAdminSettingsForm->__construct() (line 96 of modules/contrib/linkchecker/src/Form/LinkCheckerAdminSettingsForm.php).

    I’ll update further once I explore the proposed resolution. Kindly please let me know if there are any additional details I should consider and any suggestions or guidance would be greatly appreciated.

    Thanks!

  • 🇩🇪Germany marc.bau

    You can find the broken links report view at admin/reports/linkchecker. The first colum is the URL field.

    The deprecation is not causing this url issue, but need to be fixed for sure, too. :-)

  • 🇳🇿New Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

Production build 0.71.5 2024