Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In a client's setup, the editors use WYSIWYG module and CKEditor. The toolbar contains a button to add Teaser Break. However, this only inserts < !--break-- >
into the body field value and leaves summary empty. That way, the Smart Trim option to use summary if present will not work.
I've created a patch for that client which enables to use the Smart Trim option along with the teaser break.
Comments
Comment #1
drywall CreditAttribution: drywall commentedThanks for this patch. I'm trying to decide if this is going to be expected behavior under most circumstances. I guess so, right? I mean I guess if I'm utilizing the functionality, I'd expect the trimmer to honor than and not output anything past that, right?
Probably a stupid question, but how does Drupal's built-in field formatter for "summary or trimmed" handle this?
Comment #2
ttkaminski CreditAttribution: ttkaminski commentedTried the patch and it's buggy because the text filters are not applied.
Comment #3
broonHow is your setup? Are you using the same module/editor?
Text filters do still work for me. Anyways, this patch was put together rather quick, I don't expect it to cover all possible situations but that specific setup of my client.
Comment #4
michaelfavia CreditAttribution: michaelfavia commentedIFF is intentional here and stands for if and only if.
You probably want to break out the || test here for clarity but it should work as intended.
In my opinion desired functionality should be use summary if present as it is authoritative, then fallback to "break" then to our auto trimmer.
The !=0 is unnecessary as the return value from strpos is false on no string result.
Comment #5
michaelfavia CreditAttribution: michaelfavia commentedAttached patch respects the text filters and breaks out the logic a little more clearly. It also removes an unnecessary newline at the very end of the file because my vim configuration is an empty line trimming machine! ;).
Marking RTBC pending maintainer review as this is a contrib module and not core. Thank you for the great module!
This patch graciously sponsored by Second Melody.
Comment #6
michaelfavia CreditAttribution: michaelfavia commentedbroken out because its used more than once.
broken out for clarity as it is a conditional below that as logically grouped anyway
pulled in the $item['format'] dynamically from the item itself so it respects filters now.
Comment #7
Alauddin CreditAttribution: Alauddin commentedThanks @michaelfavia for the patch in #5
Applied and tested working..
Had to change the setting in display format to >> Use summary if present, honor trim settings (not the default setting)
I personally think this is the better default option where if user 'manually enters a teaser break' the system respects that manual override.
Comment #8
illeace CreditAttribution: illeace commentedI'm also running into this issue and agree with the general sentiment of the thread that this module should respect the WYSIWYG teaser break .
One edge case note about the patch in #5 -- if the <!--break--> is the very first thing in the body, then strpos will return 0 (since it's in the zeroth position of the value string). In the line:
$has_summary_or_break = !empty($item['summary']) || $break_pos;
a $break_pos value of zero will evaluate as FALSE by php, resulting in the teaser break being ignored completely.
I'm not sure why someone would want a teaser break at the very start of their body (do they want to hide the entire body in teaser lists?), so I'm not arguing this is an important issue at all, I just wanted to point it out. If it does matter to anyone, using the not identical operator (!==) effectively distinguishes a zero-position integer value from a FALSE (not in string) value:
$has_summary_or_break = !empty($item['summary']) || $break_pos !== FALSE;
Comment #9
oetseli CreditAttribution: oetseli commentedI found a flaw in the latest patch. This condition line does not treat breaks as summaries:
I changed it to use the new variable defined in the previous patch
As you can see, I also added a new variable called $honor_trim. It does what you'd think (if trim is applied even on a summary/break), but I made it into a variable to make the code more readable.
As for the question whether this should be the expected behavior or not, I definitely think it should be, but I understand it wasn't in this module by default (just look at how extra much code was needed for basic support) :). I think the view function is getting bloated so maybe 2.x should break and abstract this summary/teaser thing into a function and then just treat whatever that returns as the summary? That way adding supporting for other possible summary concepts would be easier.
Comment #10
oetseli CreditAttribution: oetseli commentedI implemented illeace's notes about $break_pos !== FALSE. I think it's a valid use case for someone to put a teaser break at the beginning of an article since that way you can ditch the teaser altogether.
So this is same as #9, but with $break_pos !== FALSE.
Comment #11
dddbbb CreditAttribution: dddbbb commentedJust tried the patch in #10 and it works fine for me.
Comment #12
toaijala CreditAttribution: toaijala commentedIt works for me aswell when 'Use summary if present, honor trim' is set, but would it be possible to add a fix that shows the specified suffix (e.g: ...) in end even when
<!--break-->
is used. Now the suffix is NOT displayed when the teaser break is used.Comment #13
atiba CreditAttribution: atiba commentedIs this already implemented in the latest dev?
I think Smart Trim is an amazing module but i'm missing this feature tbh.
Comment #14
k4v CreditAttribution: k4v commentedPatch #10 works for me =)
atiba: The patch is not in the dev version yet.
Comment #15
lolandese CreditAttribution: lolandese commentedApart from some offset, the #10 patch still applies cleanly also against the current dev. Works as expected. Please commit.
Thanks.
Comment #16
darvanenRe-rolled patch for current dev release. Would love to see this committed.
Comment #17
joelstein CreditAttribution: joelstein commentedRe-rolled against DEV. Works great!
Comment #18
AdamPS CreditAttribution: AdamPS at AlbanyWeb commented+1 for RTBC would love to see committed.
This seems to have been well-tested and useful over 2 years by various people, so worth adding to the module. Thanks!
Comment #19
markie CreditAttribution: markie at Mediacurrent commentedSorry I updated the codebase and this patch needs to be re-rolled.
Comment #20
markie CreditAttribution: markie at Mediacurrent commentedalso.. I am a moron who tried to patch this against the 8.x branch.. please hold.
Comment #22
markie CreditAttribution: markie at Mediacurrent commentedCommitted into the 7.x-1.x branch. Looking to do a full release this weekend. Please excuse my earlier silliness.
Comment #23
joelstein CreditAttribution: joelstein commentedThanks!
Comment #24
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedGreat, many thanks
Comment #26
AnybodyHi all, can we please have a new stable release? The last stable is from 2015 while the commit was in 2016... we just lost a lot of time on this issue...
Comment #27
thomas.frobieterAny news on this? :D