Problem/Motivation
When a testimonial_item block contains a long body text, the text gets visually
truncated. There is currently no way for site editors to provide a link to the full
testimonial page, and no way for end users to read the complete text.
Proposed resolution
Add an optional field_testimonial_link (Link field with title) to the
testimonial_item block content type.
When the field is filled in by the editor:
- The template renders an inline <a class="testimonial-link"> at the end of the
body <p> tag.
- A small JavaScript behavior (Drupal.behaviors.testimonialTruncate) detects whether
the body text overflows the maximum line height. If it does, it uses binary search
to truncate the visible text and appends … Read more (plain-text ellipsis + link)
inline, so the user clearly understands the link continues the current quote.
- If the text fits without truncation, the link is appended inline after the text
without ellipsis.
Remaining tasks
- Review field config (title setting, link_type)
- Review JS MAX_LINES default (currently 4)
- Add tests
User interface changes
Editors see a new optional "Link" field in the testimonial_item edit form.
Front-end: if link is set and text overflows, users see … Read more inline.
Data model changes
New link field field_testimonial_link on block_content.testimonial_item.
Existing testimonial items are unaffected (field is optional).
Issue fork lb_testimonial_blocks-3575365
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