1

I have implemented a hook_node_info() as follows:

function mymodule2_node_info(){
  return array(
    'mynode1' => array(
      'name' => 'MyNode1',
      'base' => 'mynode1',
      'description' => t('A Description of MyNode1'),
      'has_title' => TRUE,
      'title_label' => 'Title',
    ),
  );
}

I'd specified the 'base' property as 'mynode1', So I would expect that an implementation of mynode1_view() would work when this node is viewed.

function mynode1_view($node, $view_mode){

}

But I get the error messages instead:

Notice: Trying to get property of non-object in node_build_content() (line 1413 of 
C:\wamp\vhosts\mydrupal72\modules\node\node.module).
EntityMalformedException: Missing bundle property on entity of type node. in
 entity_extract_ids() (line 7880 of C:\wamp\vhosts\mydrupal72\includes\common.inc).

1 Answer 1

3

Be sure to return $node at the end of your mynode1_view function. (This is different from most hooks, which generally modify the variable by reference). You may have missed this. See this comment.

2
  • Wow! Worked like magic, thanks. Seems Drupal documentation does not make any notes on the little but hugely important detail. I'd wasted so much time already
    – okey_on
    Commented Apr 19, 2017 at 12:54
  • 2
    @okeyxyz The passed $node parameter should be modified as necessary and returned so it can be properly presented. is what he documentation says... if you feel that's unclear or ambiguous perhaps raise a feature request for improved docs? Hard to see how it can be improved though
    – Clive
    Commented Apr 19, 2017 at 13:22

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.