The example in hook_form() should use node_body_field(), which returns a node body field, with format and teaser.

Comments

jhodgdon’s picture

Title: The implementation example in hook_form() should use node_body_field() » Doc and examples for hook_form() are misleading/wrong
Version: 6.x-dev » 7.x-dev

Actually, it looks like we have problems with the hook_form() documentation in both D6 and D7.

There's a comment on the D7 page that probably needs to be incorporated into the text of the description http://api.drupal.org/api/function/hook_form/7#comment-2813 -- well I'm not sure it belongs on hook_form(). Probably the comment should be removed.

Also, in D7 it says the return value should include the title and body, but the example doesn't -- one of them must be wrong... let's see. Looking at blog_form and forum_form, it looks like you do need to include the title, so the example is wrong in D7. But since body is a Field API Field now in D7, you don't include that, so the text is wrong about that. The text should probably say something about not including any fields (such as body) because the field UI module will put them on.

In D6, it looks like the text is correct, but I agree that the example function body should use node_body_field().

Anyway, let's fix it in D7 first...

jhodgdon’s picture

Status: Active » Needs review
StatusFileSize
new2.42 KB

Here's a proposed patch for D7.

If accepted, this needs to be moved down to D6.

avpaderno’s picture

Status: Needs review » Reviewed & tested by the community

It looks perfect.

dries’s picture

Minor comment:

+++ modules/node/node.api.php	31 Aug 2010 15:36:19 -0000
@@ -967,35 +967,45 @@
+ * node/add/[nodetype] or node/[node ID]/edit.

We should probably write [node type] instead of [nodetype] when we write [node ID] and not [nodeid].

avpaderno’s picture

Status: Reviewed & tested by the community » Needs work

That is true.

jhodgdon’s picture

Can someone else re-patch? I'm on an extended cycling holiday, currently riding along the Danube river, and just occasionally checking the issue queue and/or email. I'll be back in October...

ctmattice1’s picture

Status: Needs work » Needs review
StatusFileSize
new2.27 KB

re-rolled per dries comment

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks!

jhodgdon’s picture

#7: 883454_1.diff queued for re-testing.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

avpaderno’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Patch (to be ported)

The patch needs to be ported to Drupal 6. The documentation for Drupal 6 needs to be changed differently from the documentation for Drupal 7 (see comment #1).

jhodgdon’s picture

Project: Drupal core » Documentation
Version: 6.x-dev »
Component: documentation » API documentation files

Moving to docs queue (where the file is for d6 for hooks)

sven.lauer’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new714 bytes

Re-rolling for D6, only changing the example code to use node_body_field() (and adding missing #default_value to the title field).

jhodgdon’s picture

Looks good. Committed and pushed.

jhodgdon’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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