API page: http://api.drupal.org/api/drupal/modules--field--modules--text--text.mod...

Describe the problem you have found:
The text_summary function has an early exit, if a <!--break--> tag will be found in the content. Sadly i discovered a problem if the author of the html body content didn't placed it correctly:

My body <div>is fine<!--break--></div>

This causes an shortened teaser e.g.:
My body <div>is fine
..and break up the div-structure of the surrounding page.

Not only the author of this body can make this mistake, also the ckeditor / wysiwyg didn't care about.

So i have to handle this issue on the theming layer, but i would prefer a central solution in the text.module.

Here is my patch:

Index: text.module
===================================================================
--- text.module (Revision 121)
+++ text.module (Arbeitskopie)
@@ -361,15 +361,19 @@
   }   
 
   // If a valid delimiter has been specified, use it to chop off the summary.
+  $filters = filter_list_format($format);
   if ($delimiter !== FALSE) {
-    return substr($text, 0, $delimiter);
+    $summary =  substr($text, 0, $delimiter);
+    if (isset($filters['filter_htmlcorrector'])) {
+      $summary = _filter_htmlcorrector($summary);
+    }
+    return $summary;
   }   
 
   // We check for the presence of the PHP evaluator filter in the current
   // format. If the body contains PHP code, we do not split it up to prevent
   // parse errors.
   if (isset($format)) {
-    $filters = filter_list_format($format);
     if (isset($filters['php_code']) && $filters['php_code']->status && strpos($text, '<?') !== FALSE) {
       return $text;
     }   

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

oriol_e9g’s picture

Version: 7.9 » 8.x-dev
Status: Active » Needs work
Issue tags: +Needs tests
FileSize
1.05 KB

First this will be fixed in D8 and then backported to D7, rolled a patch for Drupal 8 but we still need tests for this.

martin.weidner’s picture

Version: 8.x-dev » 7.x-dev

Hi,

I found a similar problem when using the openWysiwyg editor:
The text_summary() method was just cutting everything and the teaser was empty.

Therefore i inserted the following line to quickfix the problem:

function text_summary($text, $format = NULL, $size = NULL) {
  $text = strip_tags($text);

I know that now, all formatting gets lost in the teaser but at least there is displayed sth. Did I miss a setting or is my problem a bug within the function?

Best regards,
Martin

andypost’s picture

oriol_e9g’s picture

Version: 8.x-dev » 7.x-dev
Status: Needs review » Closed (duplicate)
Issue tags: +Needs tests

Ok, go all to the other issue.

salvis’s picture

Status: Needs work » Needs review

I don't see how the two issues should be related. The other issue is about fixing the [node:summary] token only. This issue here shows up even if you don't use the [node:summary] token.

The token will obviously suffer if text_summary() doesn't work right, but just because preparing the token uses text_summary() doesn't mean the two issues are related. Both issues need to be fixed on their own.

Status: Needs review » Needs work

The last submitted patch, summary_html_corrector-1387560-1.patch, failed testing.

oriol_e9g’s picture

Version: 7.x-dev » 8.x-dev
oriol_e9g’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
andypost’s picture

Version: 7.x-dev » 8.x-dev
Status: Closed (duplicate) » Needs review
Issue tags: -Needs tests

Status: Needs review » Needs work

The last submitted patch, 1: summary_html_corrector-1387560-1.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

goodDenis’s picture

Issue summary: View changes

I added filter "Correct faulty and chopped off HTML" (filter_htmlcorrector) in text format setting and it helps me!
This is example code:
$summary = text_summary($node->get('body')->value, 'full_html');

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Juhi Rathi’s picture

htmlentities() will simply solve the issue. This will convert all applicable characters to HTML entities.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

There are a few issues about the trimmed text. Adding what I think is the closest fit as a related issue.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Closed (duplicate)

Seems to be a duplicate of #3022299: Make manual teaser break (<!--break-->) a configuration property closing this one as that one is more ahead.

if you disagree please reopen explaining why thanks!