Problem/Motivation

If HTML encoded elements exist in trimmed field and "Display More link only when content is trimmed?" is checked but "Strip HTML" is not, More link will display even if content is shorter than the defined limit. This is a direct result of this commit done for issue #3108420.

Steps to reproduce

Create View with Smart Trimmed field with HTML content that includes HTML encoded values. Be sure length of content is less than limit set in Smart Trim formatter.
Select "Display More link?" and "Display More link only when content is trimmed?" and leave "Strip HTML" unchecked.
Results will display "More" link even though content length is less than the defined limit.

Proposed resolution

Address the "#format == NULL" problem defined in issue #3108420 more directly such that it does not affect fields with HTML encoded values. I can't be more specific than that because I don't fully understand the use case of that issue. I will attach a patch file that works for me. Since I don't have the "#format == NULL" use case I can't say that this simple solution is the best approach.

Issue fork smart_trim-3512933

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

sean_fremouw created an issue. See original summary.

sean_fremouw’s picture

Probably too simple patch.

markie’s picture

Please create an MR with this patch.. Thank you

haritha c made their first commit to this issue’s fork.

haritha c’s picture

Status: Active » Needs review
StatusFileSize
new43.54 KB

Fixed issue #3512933—'More' link now only shows if visible text exceeds the trim limit. For short content (e.g., 20 chars) with a 50-char limit, it no longer displays . Patch (version 5) from branch 3512933-smart_trim_fixes attached.

markie’s picture

Status: Needs review » Needs work

The MR doesn't come close to matching the patch and has a lot of CS errors.

haritha c’s picture

StatusFileSize
new33.54 KB

I have worked on resolving the reported issues. Some of the PHPUnit test issues are fixed, but a few still remain. However, the functionality is working fine. Locally, my code does not show any errors, but I am still facing issues in the pipeline. Could you provide any suggestions on how to debug or resolve this? Thanks!

haritha c’s picture

Status: Needs work » Needs review

I have fixed the PHPCS and unit test issues for smart_trim-3512933. Please review and let me know if any further changes are needed.

haritha c’s picture

Assigned: Unassigned » haritha c

peri22 made their first commit to this issue’s fork.

peri22’s picture

It looks like this issue was already fixed on the '2.x' branch by #3558917: " " issue

The problem was caused by the '#is_trimmed' check comparing the raw '$original_output' against an entity-decoded '$output'. Because of that, any encoded entity caused a mismatch and made the "More" link appear by mistake.

I manually double-checked the exact setup on '2.x' HEAD (Drupal 11.4, "Strip HTML" off, 'link_trim_only' on) with various entities (accents, nbsp, ampersands, and quotes) inside and outside of markup. The false "More" links no longer appear, but actual over-length content still gets trimmed properly.

MR !132 adds a solid regression test for this (which properly fails on the older code). As for MR !108 and !109, they are from March 2025 and conflict with the current '2.x' branch, so I think they can be closed.

  • ultimike committed 74121246 on 2.x authored by peri22
    fix: #3512933 Add a regression test for encoded entities and the More...
ultimike’s picture

Status: Needs review » Fixed

@peri22 - very good, I think the additional test is just what we need to close this issue.

Merged!

-mike

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.