Sometimes you need to be able to insert a teaser break before the admin settings trimmed char cutoff. These lines should help with that. Not able to provide a patch from where I am now.

/**
* Implements hook_field_formatter_view().
*/
function trimmed_plaintext_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
switch ($display['type']) {
case 'text_plain_trimmed':
foreach ($items as $delta => $item) {
+ $delimiter = strpos($item['value'], '

');
+ if ($delimiter) {
+ $output = preg_replace('/\s\s+/', ' ', strip_tags(substr($item['value'], 0, $delimiter)));
+ } else {
$output = preg_replace('/\s\s+/', ' ', strip_tags(_text_sanitize($instance, $langcode, $item, 'value')));
+ }

Comments

j0rd’s picture

@perarnet Seems like this may be a useful feature. I'm going to need a patch to be able to incorporate this for you though, as it seems that when posting your code in here, drupal.org has stripped away the <!--break-->

So please post the code properly between PHP tags or something so I can see it properly and I'm not wasting my time trying to guess what you code is.

I'm just as lazy as you are :D

perarnet’s picture

StatusFileSize
new501 bytes

Here's a patch. The git repo was not consistent with the version for download, so just used a diff output.

j0rd’s picture

We should be using text_summary() to create the teaser for us. Problem is I'm tripping the 'BREAK' out before running it though text_summary().

So while this bug exists, I don't believe your patch solves it properly.

Also if you're going to do a diff, use these arguments `diff -urN`. Otherwise, I'm unsure how to apply it with `patch`

j0rd’s picture

Status: Active » Needs work

needs work.

j0rd’s picture

This problem was also created by this patch
#1350902: Should you be stripping tags before trimming

j0rd’s picture

Also this core bug causes a problem, as _text_sanitize & filtered_html remove the BREAK tag, thus text_summary never finds it.

#881006: Regression: 'break' tag doesn't work with Filtered HTML

j0rd’s picture

Real problem is Drupal's stupidity. What should happen when a body is saved and has a BREAK, $item['summary'] should get populated, and then my filter module should only have to test for that.

Why should ever single field_formatter have to test for $item['summary'] and if it doesn't exist summarize the text myself.

This not only adds a bunch of additional logic required for every field_formatter, but it forces me to re-computate the value every time, instead of doing it once and saving the result.

j0rd’s picture

StatusFileSize
new1.69 KB

Here's a patch which would work once #881006: Regression: 'break' tag doesn't work with Filtered HTML is fixed.

While your patch above would work as expected, the HTML would never be passed through input filters, which could do replacements in the HTML and thus change the text before the BREAK.

My solution is more optimal, but won't work (if you're using filtered_html) until the above issue is resolved in core.

perarnet’s picture

StatusFileSize
new1.04 KB

Adding < !-- > to allowed tags in input format lets the patch work, but still need to add the fix to case 'text_plain_trimmed'.

Here's a patch that works for me.

greg boggs’s picture

Teaser breaks can be controlled using Display Suite on a per display basis which may be helpful for others finding this thread.

Also, getting editor "teaser" break to work with filtered HTML using the regular summary/teaser requires the same edit to accept

, so I think this patch should be committed along with an update to readme.txt explaining how to do it!

greg boggs’s picture

Issue summary: View changes
Status: Needs work » Needs review