This patch allows for zero length teaser summaries. It moves the "Unlimited" option to -1, so that there can be a 0 length character option.

One of my clients didn't want the summary text to show up in the teaser. Make the summary text trimmed to 0 fixed that.

Comments

Status: Needs review » Needs work

The last submitted patch failed testing.

robloach’s picture

Status: Needs work » Needs review
Issue tags: +teaser, +summary, +text_summary
StatusFileSize
new5.71 KB

Updated the test to test the zero length summary.

tic2000’s picture

I wonder if in this case we should add in text_summary a check at the top so we just return '' if $size == 0.

dries’s picture

I haven't tried the patch yet but wouldn't that show -1 in the UI?

Status: Needs review » Needs work

The last submitted patch failed testing.

deekayen’s picture

Status: Needs work » Needs review

core tests are broken

tic2000’s picture

@Dries
I didn't try the patch either, but by looking at it I would say it will show "Unlimited" and add 0 in the UI.

robloach’s picture

StatusFileSize
new17.29 KB
new5.99 KB

Takes tic2000's suggestion at #3 into consideration and puts a check to see if the $size is 0 before future parsing. Thanks for giving it a look, Dries. I've attached a screenshot of what it looks like to the user. Thanks!

tic2000’s picture

Status: Needs review » Needs work
+  elseif ($size === 0) {
+    // To save time on trimming the summary, evaluate to see if an empty text
+    // summary is desired.
+    return '';
+  }

elseif should be a simple if.

Note: Right now in HEAD, if I'm not mistaken, $size = variable_get('teaser_length', 600); will always result to 600 because there is no UI available where you can change that. The UI changes teaser_length_$node->type.

robloach’s picture

That seems like a bug to me... Should teaser_length be moved over to each the text summary length for each content type? The data is being used when it will actually never exist on a Drupal 7 installation? That seems wrong.

tic2000’s picture

Yes, but it's not this patch's issue to solve.
I have an issue opened about the teaser length #504564: Make summary length behave with fields.
A patch with elseif converted to a simple if would make this patch good to go IMO.

robloach’s picture

Status: Needs work » Needs review
StatusFileSize
new5.98 KB

Testing bot, I choose you!

tic2000’s picture

Status: Needs review » Reviewed & tested by the community
webchick’s picture

Status: Reviewed & tested by the community » Needs work

Hm. Is there a use case for this? This feels like "So install Views and create a title list then, ya knob!" ;)

But at any rate, if we change the summary length to 0, there's no reason to display the summary field.

tic2000’s picture

Install Views just to get a list of titles when you can get so easily that list with this change?
My main grip against the teaser length is that it gives me a list instead of a text field so I'm free to set the exact length I want with -1 or blank for unlimited. Yes I know, I can achieve that with Views too or I can _form_alter the form.

The teaser length doesn't act on the summary field, it acts on the body field when there is no summary.

webchick’s picture

But if the summary isn't displayed (since it's truncated to 0 characters), what's the point in displaying a field for it?

yched’s picture

Setting 'trimmed length to 0' definitely sounds more like setting the body field to 'hidden' in 'teaser' build mode - well, in the not-(yet?)-in-core Field UI...

Also note that #504564: Make summary length behave with fields aims at making trimmed length a field formatter setting, which is definitely the way forward.
Patch needs a reroll and testers.

webchick’s picture

@yched: Oh. Duh. Yes.

In that case, that probably makes this won't fix, no?

tic2000’s picture

IMO it doesn't. It just gives you 2 options to achieve the same thing. Also it means it gives you the option to say, if the node is not worthy of a separate summary just show the title, if it is, show the summary.
I repeat, the 0 length means the body field will be trimmed to 0. Even if the setting is set to 0, but you have a summary, the summary will still be shown. You can test that now. Set the teaser length to 200 and add a node with a VERY long summary. The summary will be in full length on the front page.

rooby’s picture

Version: 7.x-dev » 8.x-dev
Component: node system » field system

I agree with tic2000,
You can set the field display to hidden on teasers if you don't want any summary or body test on the teaser.

However, if you want to show the summary text only, and if there is not any summary text then show nothing, you cannot do that.
You can have summary or trimmed, but you can't just have summary or nothing.

This is because trim_length is set to validate using element_validate_integer_positive.

So I think we either need to be able to set trim length to zero or we have a new field formatter that is just "Summary", that will display the summary if there is one, otherwise will display nothing.

swentel’s picture

Component: field system » text.module

Moving to text.module - there might be other text issues in the 'field system' component.

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.

noah’s picture

Issue summary: View changes

In case anyone else comes across this thread looking to achieve this in D7, I did it with a simple custom field formatter (in a custom module):

function [module]_field_formatter_info() {
  $formats = array(
    'summary_only' => array(
      'label' => t('Summary only'),
      'field types' => array('text_with_summary'),
      'description' => t('Displays the explicit summary if one exists, otherwise nothing.'),
    ),
  );
  return $formats;
}
function [module]_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  if ($display['type'] == 'summary_only') {
    foreach ($items as $delta => $item) {
      $markup = '';
      if (isset($item['safe_summary']) && ($item['safe_summary'] != '')) $markup = $item['safe_summary'];
      $element[$delta] = array('#markup' => $markup);
    }
  }
  return $element;
}

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.

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.

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.

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 » Postponed (maintainer needs more info)

Think this is outdated. Adding -1 doesn't seem like something that will be committed.

And in the manager display you can change to trimmed which shows the body and not summary.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Since there hasn't been a follow up, going to close for now.

Thanks