Field options "Rewrite results" and "Link to the Content" applied together is not working as expected

Created on 24 October 2015, almost 9 years ago
Updated 20 August 2024, 18 days ago

Problem/Motivation

If a text field is added to a view configured with 'Link to the Content' and at the same time the result ist to be rewritten e.g. by trimming the field to a max. number of characters, the output does not behave as expected.

E.g. use field 'Title' and leave all field attributes on the default values, activate 'Link to the Content' and 'Trim this field to a maximum number of characters' (10) and - for simplicity - deactivate other suggested options. This will not output anything at all.

Another related symptom can be observed if 'Link to the Content' is active and the only other option in 'REWRITE RESULTS' is 'Strip HTML tags': this will remove the link from the output.

I observed that in the PHP method (namespace Drupal\views\Plugin\views\field) FieldPluginBase::renderText() not the field content is rendered but the compete link element (e.g. "<a href="/de/software/xtrack" hreflang="de">XTrack GPS Tracking Tool</a>") including HTML markup generated by 'Link to the Content'.

Shouldn't the markup generated by 'Link to the Content' be applied after the REWRITE rules?

Steps to reproduce

  1. Install Drupal 11.x.
  2. Create a content type with a text field (e.g., "Title").
  3. Add some content with titles longer than 10 characters.
  4. Create a view displaying this content.
  5. Add the "Title" field to the view and configure it:
  6. Enable "Link to the Content" under Rewrite Results.
  7. Enable "Trim this field to a maximum number of characters" and set it to 10.
  8. Ensure other options (like "Strip HTML tags") are unchecked.
  9. Save the view and check the output.

Proposed resolution

Update the FieldPluginBase::advancedRender method to handle "Link to the Content" better by ensuring that text modifications (like trimming or HTML stripping) are applied before the link is added. This change will ensure that any alterations to the text happen first, and the link wraps around the final output correctly.

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Viewsย  โ†’

Last updated about 12 hours ago

Created by

๐Ÿ‡จ๐Ÿ‡ญSwitzerland jzanger

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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 Amber Himes Matz Portland, OR USA

    Looking at this issue again at DrupalCon at the Bug Smash table.

    Looks like a possible intermittent test failure. Re-adding this to the queue.

  • last update 4 months ago
    Custom Commands Failed
  • Status changed to Needs work 4 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States Amber Himes Matz Portland, OR USA

    Also, looks like the patch needs rerolling.

  • First commit to issue fork.
  • Merge request !7988Resolve #2600456 "Field options rewrite" โ†’ (Open) created by Nephele
  • Pipeline finished with Failed
    4 months ago
    Total: 177s
    #168061
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States Nephele

    I've converted the patch into a merge request (effectively rerolling against 11.x) and added a line of code to fix the phpstan errors that made the latest tests fail.

  • Status changed to Needs review 4 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States Nephele

    Updating tags

  • Status changed to Needs work 4 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Tagging for an issue summary update. Summary should use the standard issue template please.

    MR appears to have a PHPCS error

    Added 2 nitpicky change requests to the MR

    Thanks!

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia VinmayiSwamy

    Hi, I tested the MR !7988 by following the steps outlined in the issue summary. Hereโ€™s what I observed:

    1. The "Title" field now correctly trims to 10 characters and the link is applied as expected.
    2. Text manipulations such as trimming and HTML stripping are processed before the link is applied, resolving the issue where the link was not correctly wrapping around the modified text.

    The MR addresses the issue and ensures that "Link to the Content" integrates properly with text rewrites.

    Attaching screenshots for reference.

    Iโ€™ve also made updates to the issue summary. Kindly please review the changes and let me know if any further adjustments are needed.

Production build 0.71.5 2024