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.
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | node-body-field-hasbody-223771-17.patch | 1.46 KB | cburschka |
| #16 | node-body-field-hasbody-223771-16.patch | 1.43 KB | cburschka |
| #14 | node-body-field-hasbody-223771-14.patch | 1.43 KB | cburschka |
| #10 | node-body-field-hasbody-223771-10.patch | 1.44 KB | amitaibu |
| #2 | node-body-field-hasbody-223771-2.patch | 1.82 KB | cburschka |
Comments
Comment #1
cburschkaNote: My last references to node_body_form should be node_body_field, naturally.
Comment #2
cburschkaOn 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.)
Comment #3
Steve Dondley commented+1 This is needed. Too bad it looks like it got overlooked.
Comment #4
Steve Dondley commentedComment #5
Anonymous (not verified) commentedSteve, have you applied the patch and it works properly? If so, change the status to "patch (reviewed & tested by the community).
Comment #6
Steve Dondley commentedI 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.
Comment #7
livingegg commentedThis bug also applies to version 5.x. It would be nice to have a fix.
Comment #8
damien tournoud commentedBugs 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.
Comment #9
mrgoltra commentedsubscribing. I would really love to upgrade my site to 6 but I can't until this issue is fixed.
Comment #10
amitaibuRe-roll Arancaytar's patch against HEAD with slight modification (
return array()).I've applied patch, and it works.
Comment #12
hanoiiI 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?
Comment #13
nonsieSubscribing
Comment #14
cburschkaI cannot apply the patch in #10, and it seems neither can pifrbot.
Here's a reroll.
Comment #15
mikejoconnor commentedArancaytar,
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:
Comment #16
cburschkaWhoops. You're right, of course. I've remarked the same point on countless patches! :P
Here we go again.
Comment #17
cburschkaIn 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.
Comment #18
dries commentedThis patch makes sense to me, and all the tests pass. I'm marking this RTBC and will proceed committing it later today.
Comment #19
cburschkaYay! :)
Comment #20
dries commentedCommitted to CVS HEAD. Thanks!
Comment #22
grendzy commentedComment #23
vthirteen commentedsubscribe.
Comment #24
Max_Headroom commentedHas this been ported? I'm on 6.20 and still have this problem with body showing in blog.
Comment #25
Max_Headroom commentedWork around without hacking:
Comment #26
Anonymous (not verified) commentedI'm going to guess this is a won't fix for D6, since D6 commits focus on security fixes at this point.
Comment #27
Anonymous (not verified) commentedChanging issue status to reflect that it was fixed in 7.x.