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.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | Screenshot 2025-03-15 150557.png | 33.54 KB | haritha c |
| #6 | Smart trim.png | 43.54 KB | haritha c |
| #2 | do_not_strip_html_encoded_entities-3512933-1.patch | 740 bytes | sean_fremouw |
Issue fork smart_trim-3512933
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
Comment #2
sean_fremouw commentedProbably too simple patch.
Comment #3
markie commentedPlease create an MR with this patch.. Thank you
Comment #6
haritha c commentedFixed 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.
Comment #7
markie commentedThe MR doesn't come close to matching the patch and has a lot of CS errors.
Comment #9
haritha c commentedI 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!
Comment #12
haritha c commentedI have fixed the PHPCS and unit test issues for smart_trim-3512933. Please review and let me know if any further changes are needed.
Comment #13
haritha c commentedComment #16
peri22 commentedIt 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.
Comment #18
ultimike@peri22 - very good, I think the additional test is just what we need to close this issue.
Merged!
-mike