0
function heihachi_form_alter(&$form, $form_state, $form_id) {
    if ($form_id == 'ipaper_node_form') {
           unset($form['body']);
        }
}

the code above removed body field in node/add/ipaper. But how can i remove body inside a node? (mysite.com/node/4420 for example).

And 2nd question is: i did print_r($form) inside mymodule.module and now im watching in the page source code and see this:

Array
{

    [#node] => stdClass Object
        (
            [uid] => 1
            [name] => heihachi

i am on the right way if i use this construction to print the name for example: $form['#node'] => ['name'] ?? Guess not.. :) That stdClass Object is confusing me :(

3 Answers 3

3

A better approach is to edit the content type settings and omit body altogether.

In Drupal 6, you can do this by going to /admin/content/types/ipaper and leave the "Body field label" empty.

In Drupal 7, go to /#overlay=admin/structure/types/manage/ipaper/fields and delete the Body field.

If you really need to keep old content in the node body, then use hook_nodeapi() with $op == 'view to unset $node->body

1

The if $form['body'] is where the output is being sourced from, unset should work fine, but as this is form_alter I'm not entirely sure whether the node will already have been rendered by the time it's called.

You'll be able to get to the node name using:

$form['#node']->name

rather than:

$form['#node']['name'] 

which would be what you'd use if it was an array rather than an object

3
  • Thanks... now just 1 question left: how to unsed body inside node :) Commented Sep 5, 2011 at 16:11
  • Is the problem with unsetting the body in the node that this unset code is only getting called for the form 'ipaper_node_form'? Whereas you want to remove the body from other nodes?
    – Sam Martin
    Commented Sep 5, 2011 at 17:33
  • inside from node view. From node/add/ipaper i've successfully removed it Commented Sep 5, 2011 at 18:40
1

You should implement hook_nodeapi:

function heihachi_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  if ($op == 'prepare') {
    unset($node->body);
  }
3
  • Thanks, but its impossible with just hook_form_alter? Commented Sep 5, 2011 at 19:13
  • as far as I am aware, it's impossible. Commented Sep 6, 2011 at 7:08
  • oops, when im viewing node/4480 - node->body is still there, whats wrong? I shouldn't use 'prepare'? Commented Sep 6, 2011 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.