If you enter a non-empty summary, but leave Full text empty, then saving the node will save nothing. When re-editing the node, both the summary and Full text will be empty.

To reproduce:
1. Create a new Page or Article, or edit an existing one.
2. Click on "Edit Summary".
3. Enter some text in the summary textarea, but leave the Full text textarea empty (or delete what's there).
4. Click Save.
5. Edit the page again. Both the summary and the Full text textareas will be empty.

I have not changed the trim length from the default. This is on a fresh 7.x-dev build downloaded on 2009-10-27.

My intention in this scenario was to try to create a Page that would display in full (without a teaser) on the front page.

(I am a newbie and have no idea if I chose the correct Component.)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pshahmumbai’s picture

Bug is confirmed.

When you remove the content from the full text area, the row data is also getting deleted from the database table 'field_data_body'

Update :

./modules/node/node.module:function node_save($node) : If the full text is not present then the $node does not contain any value for $node->body

["body"]=> array(1) { ["zxx"]=> array(0) { } }

The correct values should be :

["body"]=> array(1) { ["zxx"]=> array(1) { [0]=> array(4) { ["summary"]=> string(22) "This is a sample text" ["value"]=> string(0) "" ["format"]=> string(1) "1" ["value_format"]=> string(1) "1" } } }

It considers it as the same situation as both the body summary and full text field being empty.

aspilicious’s picture

Confirmed

furamag’s picture

I think I found where problem is. Function text_field_is_empty (modules/field/modules/text/text.module) return TRUE if body field is empty even if summary is not empty. After that function _field_filter_items (modules/field/field.module) unset body field (and summary field too).
Current code for text_field_is_empty function is:

function text_field_is_empty($item, $field) {
  if (empty($item['value']) && (string) $item['value'] !== '0') {
    return TRUE;
  }
  return FALSE;
}

We should use following code:

function text_field_is_empty($item, $field) {
  if (empty($item['value']) && (string)$item['value'] !== '0') {
    if ($field['type'] == 'text_with_summary') {
      return (empty($item['summary']) && (string)$item['summary'] !== '0');
    }
    else {
      return TRUE;
    }
  }
  return FALSE;
}

Also I found patch for this function - http://drupal.org/files/issues/body-as-field.patch . But this patch failed test (http://qa.drupal.org/pifr/test/5791) so we can't use this patch. Instead of that we can create another patch:

 function text_field_is_empty($item, $field) {
   if (empty($item['value']) && (string)$item['value'] !== '0') {
-    return TRUE;
+    if ($field['type'] == 'text_with_summary') {
+      return (empty($item['summary']) && (string)$item['summary'] !== '0');
+    }
+    else {
+      return TRUE;
+    }
   }
   return FALSE;
 }
dhalbert’s picture

Title: Non-empty summary and empty Full text lose all content when saved » Non-empty Summary and empty Body both become empty when saved.

Changed issue title to match terminology in current 7.x: "Full text" is now "Body". Bug is still present.

Brief repeat of scenario with current terminology:
1. Create a new Article or Basic Page with some text in the Summary and no text in the Body.
2. Save it. When you look at it again, there will be nothing in both the Summary and Body

ygerasimov’s picture

Status: Active » Needs work
FileSize
871 bytes

Here is patch for #3. But there is another problem that is raised after applying it. When you Edit the node with Summary only, summary field collapsed. Also I believe we need to make test for this case (empty body and not empty summary).

Damien Tournoud’s picture

+    if ($field['type'] == 'text_with_summary') {
+       return (empty($item['summary']) && (string)$item['summary'] !== '0');
+    }
+    else {
+      return TRUE;
+    }

There is a slight indenting issue here.

ygerasimov’s picture

FileSize
870 bytes

Yes. Identing issue fixed.

yched’s picture

[edited out, I was on crack]

ygerasimov’s picture

Component: node.module » field system
Status: Needs work » Needs review
FileSize
1.4 KB

Here is patch including fix for javascript. Please review.

ygerasimov’s picture

Here is patch with test.

yched’s picture

Status: Needs review » Needs work
+++ modules/field/modules/text/text.test	14 Oct 2010 17:54:04 -0000
@@ -372,6 +377,26 @@ class TextSummaryTestCase extends Drupal
+    // Translate the article in french.

Sorry ?

+++ modules/field/modules/text/text.test	14 Oct 2010 17:54:04 -0000
@@ -372,6 +377,26 @@ class TextSummaryTestCase extends Drupal
+    ¶

white line should have no spaces

Other than that, patch looks good.

Powered by Dreditor.

ygerasimov’s picture

Status: Needs work » Needs review
FileSize
3.11 KB

Thank you for the review. I have cleaned the patch.

dhalbert’s picture

Patch tested and works as expected, both when creating new content and editing existing content. Thank you!

Displayed on its own page, the item appears empty.
Displayed on the front page, the summary is shown, with a "Read more." Still a bit pathological, but now there is no chance of losing the summary if one clears the body.

yched’s picture

Status: Needs review » Reviewed & tested by the community

fine, thanks !

webchick’s picture

Priority: Normal » Major
Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks!

sun’s picture

Status: Fixed » Needs work
+++ modules/field/modules/text/text.module	15 Oct 2010 05:27:26 -0000
@@ -171,7 +171,12 @@ function text_field_load($entity_type, $
 function text_field_is_empty($item, $field) {
   if (empty($item['value']) && (string) $item['value'] !== '0') {
-    return TRUE;
+    if ($field['type'] == 'text_with_summary') {
+      return (empty($item['summary']) && (string)$item['summary'] !== '0');
+    }
+    else {
+      return TRUE;
+    }
   }
   return FALSE;

Erm. This entire condition construct looks very odd.

The initial condition likely meant

isset($item['value']) && $item['value'] === ''

Same for the condition that has been introduced.

Powered by Dreditor.

yched’s picture

This also catches $item['value'] === NULL, or $item === array()
I'd leave it that way.

sun’s picture

Alright, so we actually mean:

!isset($item['value']) || $item['value'] === ''
sun’s picture

Status: Needs work » Needs review
FileSize
924 bytes
dhalbert’s picture

drupal.text-empty.19.patch tested. OK - works same as previous one.

yched’s picture

Status: Needs review » Reviewed & tested by the community

Sure.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.