The settings page for all content types (including blog entries) states clearly that to remove the body field of a node, the label must be blanked. However, while content types handled by the node module will display this expected behavior, removing the body label on the blog entry will only remove the label, not the field.

While node_content_form() checks the has_body property before generating a field,

  if ($type->has_body) {
    $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
  }

blog_form() does not do so:

  $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);

node_body_field() does not actually contain any logic regarding field labels:

function node_body_field(&$node, $label, $word_count) {

  // Check if we need to restore the teaser at the beginning of the body.
  $include = !isset($node->teaser) || ($node->teaser == substr($node->body, 0, strlen($node->teaser)));

  $form = array(
    '#after_build' => array('node_teaser_js', 'node_teaser_include_verify'));

  $form['#prefix'] = '<div class="body-field-wrapper">';
  $form['#suffix'] = '</div>';

  $form['teaser_js'] = array(
    '#type' => 'textarea',
    '#rows' => 10,
    '#teaser' => 'edit-body',
    '#teaser_checkbox' => 'edit-teaser-include',
    '#disabled' => TRUE,
  );

  $form['teaser_include'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show summary in full view'),
    '#default_value' => $include,
    '#prefix' => '<div class="teaser-checkbox">',
    '#suffix' => '</div>',
  );

  $form['body'] = array(
    '#type' => 'textarea',
    '#title' => check_plain($label),
    '#default_value' => $include ? $node->body : ($node->teaser . $node->body),
    '#rows' => 20,
    '#required' => ($word_count > 0),
  );

  $form['format'] = filter_form($node->format);

  return $form;
}

I submit this issue to blog.module as it could easily solve the problem by emulating node.module in checking for has_body before generating a field. However, perhaps this check should be centralized to node_body_form, which would work to limit these errors in nodes by contrib modules. node_body_form already gets a node, which has a type - checking this type for the presence of a body field would make much sense.

Comments

cburschka’s picture

Note: My last references to node_body_form should be node_body_field, naturally.

cburschka’s picture

Title: Blog entries have body fields even if body was disabled » node_body_field does not check $type->has_body
Component: blog.module » node.module
Status: Active » Needs review
StatusFileSize
new1.82 KB

On second thought, perhaps the node_body_field solution makes even more sense than the blog_form fix. I'm moving it into the node.module queue now, and submitting a patch to node.module.

The main advantage of this fix: It ensures expected behavior on node forms without requiring all node modules to reimplement central logic. If the content type settings state that I can disable the body field, then the body field should be gone regardless of what module is handling this node.

(Attached patch also removes the now redundant check from node_content_form, as well as a typo in a comment (mutlistep) I happened to notice.)

Steve Dondley’s picture

+1 This is needed. Too bad it looks like it got overlooked.

Steve Dondley’s picture

Version: 6.x-dev » 6.4
Anonymous’s picture

Steve, have you applied the patch and it works properly? If so, change the status to "patch (reviewed & tested by the community).

Steve Dondley’s picture

I have not tried the patch. I used the suggestion in the original post and modified blog.module. So I'm uncomfortable saying this has been tested and reviewed. I think someone more familiar with the base code should weigh in on this one. Though I can see no reason why the code above would cause problems, I've been burned enough by the law of unintended consequence to say anything definitively.

livingegg’s picture

This bug also applies to version 5.x. It would be nice to have a fix.

damien tournoud’s picture

Version: 6.4 » 7.x-dev
Status: Needs review » Needs work

Bugs get fixed in the current development version, then backported.

The patch in #2 is an API change, because (1) node_body_field() behavior is modified, and (2) because $form now contains the 'body_field' key unconditionally. As such, the change should not go in D6 as is. Just changing blog_form should be enough for D6.

mrgoltra’s picture

subscribing. I would really love to upgrade my site to 6 but I can't until this issue is fixed.

amitaibu’s picture

Status: Needs work » Needs review
StatusFileSize
new1.44 KB

Re-roll Arancaytar's patch against HEAD with slight modification (return array()).
I've applied patch, and it works.

Status: Needs review » Needs work

The last submitted patch failed testing.

hanoii’s picture

I have found this as well on one of my projects and I wanted to submit a patch for D5 which involves changing just blog_form() as suggested in #8. What's the proper way of submit such a patch? Shall I create a new issue or submit it here?

nonsie’s picture

Subscribing

cburschka’s picture

Status: Needs work » Needs review
StatusFileSize
new1.43 KB

I cannot apply the patch in #10, and it seems neither can pifrbot.

Here's a reroll.

mikejoconnor’s picture

Status: Needs review » Needs work

Arancaytar,

I think this is a great approach. Just two small critiques. The comments run over 80 characters, and I don't think we put comments on the same line as other code. I looked through a few core files and all of the comments are above subject of the comment. I'm marking as code needs work, only because of formatting. I would suggest something like this:

function node_body_field(&$node, $label, $word_count) {

  $type = node_get_types('type', $node);

  // Do not generate a body field if the type does not specify one.
  if (!$type->has_body) {
    return array();
  }

cburschka’s picture

Status: Needs work » Needs review
StatusFileSize
new1.43 KB

Whoops. You're right, of course. I've remarked the same point on countless patches! :P

Here we go again.

cburschka’s picture

StatusFileSize
new1.46 KB

In fact, since we only use $type for that one check, I think PHP 5 might allow node_get_types(...)->has_body, but I'm not sure. I also don't know if it's proper code.

Here is a separate patch that saves a few lines by doing that. I got no syntax errors, but use the one above if the bot complains.

dries’s picture

This patch makes sense to me, and all the tests pass. I'm marking this RTBC and will proceed committing it later today.

cburschka’s picture

Status: Needs review » Reviewed & tested by the community

Yay! :)

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks!

Status: Fixed » Closed (fixed)

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

grendzy’s picture

Version: 7.x-dev » 6.x-dev
Status: Closed (fixed) » Patch (to be ported)
Issue tags: +Needs backport to D6
vthirteen’s picture

subscribe.

Max_Headroom’s picture

Has this been ported? I'm on 6.20 and still have this problem with body showing in blog.

Max_Headroom’s picture

Work around without hacking:

/**
 * Implementation of hook_form_alter().
 */
function MYMODULE_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'blog_node_form':
      unset ($form['body_field']) ;
      break;
  }
}
Anonymous’s picture

Status: Patch (to be ported) » Closed (won't fix)

I'm going to guess this is a won't fix for D6, since D6 commits focus on security fixes at this point.

Anonymous’s picture

Version: 6.x-dev » 7.x-dev
Status: Closed (won't fix) » Closed (fixed)

Changing issue status to reflect that it was fixed in 7.x.