Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1056795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:46:04+00:00 2026-05-16T17:46:04+00:00

I have a module with four node types declared. My problem is, hook_load, hook_view

  • 0

I have a module with four node types declared. My problem is, hook_load, hook_view is never called. I used drupal_set_message to find out if certain hook is being called. And I found out hook_load, hook_view isn’t. Just to give you clear picture, here’s my structure of hook_load

HERE’S UPDATED ONE

function mymodule_node_info(){
   return array(
      'nodetype1' => array(
         'name' => t('nodetype1'),
         'module' => 'mymodule_nodetype1',
         'description' => t('....'),
         'has_title' => TRUE,
         'title_label' => t('Title'),
         'has_body' => TRUE,
         'body_label' => t('Body'),
     ),
     'nodetype2' => array(
         ......
         'module' => 'mymodule_nodetype2',
         ......
     ),
     'nodetype3' => array(
         ......
         'module' => 'mymodule_nodetype3',
         ......
     ),
     'nodetype4' => array(
         ......
         'module' => 'mymodule_nodetype4',
         .......
     ),
 );

 }

function mymodule_nodetype1_load($node){    
   $result = db_query('SELECT * from {nodetype1table} WHERE vid = %d'
               $node->vid
           );   
   drupal_set_message("hook_load is provoked.","status");
   return db_fetch_object($result);
}

I don’t know why it is not called. I wrote this code base on drupal module writing book and follow the instructions. I’ve tried sample code from that book and it works ok. Only my code isn’t working. Probably because of multiple node types in one module. Any help would be highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:46:04+00:00Added an answer on May 16, 2026 at 5:46 pm

    Your code doesn’t work because hook_load() and hook_view() aren’t module hooks: they’re node hooks. The invocation is based off of content type names, not module names.

    So, first you need to have declared your content types using hook_node_info():

    function mymodule_node_info() {
      $items = array();
    
      $items['nodetype1'] = array(
        'name' => t('Node Type 2'),
        'module' => 'mymodule_nodetype1',
        'description' => t("Nodetype 1 description"),
      );
      $items['nodetype2'] = array(
        'name' => t('Node Type 2'),
        'module' => 'mymodule_nodetype2',
        'description' => t("Nodetype 2 description"),
      );
      $items['nodetype3'] = array(
        'name' => t('Node Type 2'),
        'module' => 'mymodule_nodetype3',
        'description' => t("Nodetype 3 description"),
      );
    
      return $items;
    }
    

    Then, you need to use the name of the module you specified for each content type declared in hook_node_info() for your node hooks. That is, mymodule_nodetype1_load(), mymodule_nodetype2_view(), etc.


    Edit

    If you’re trying to have a non-node based module fire when a node is viewed or loaded, you need to use hook_nodeapi():

    function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
      switch ($op) {
        case 'view':
          mymodule_view_function($node);
          break;
        case 'load':
          mymodule_load_function($node);
          break;
      }
    }
    

    Replace mymodule_load_function() and mymodule_load_function() with your own custom functions that are designed to act on the $node object.


    Edit 2

    Besides the syntax error in your hook_load() implementations, there’s a piece of your code outside of what you’re providing that’s preventing the correct invocation. The following code works (if you create a nodetype1 node, the message “mymodule_nodetype1_load invoked” appears on the node): perhaps you can compare your entire code to see what you’re missing.

    function mymodule_node_info() {
      return array(
        'mymodule_nodetype1' => array(
          'name' => t('nodetype1'),
          'module' => 'mymodule_nodetype1',
          'description' => t('....'),
          'has_title' => TRUE,
          'title_label' => t('Title'),
          'has_body' => TRUE,
          'body_label' => t('Body'),
        ),
        'mymodule_nodetype2' => array(
          'name' => t('nodetype2'),
          'module' => 'mymodule_nodetype2',
          'description' => t('....'),
          'has_title' => TRUE,
          'title_label' => t('Title'),
          'has_body' => TRUE,
          'body_label' => t('Body'),
        ),
      );
    }
    
    function mymodule_nodetype1_form(&$node, $form_state) {
      // nodetype1 form elements go here
    
      return $form;
    }
    
    function mymodule_nodetype2_form(&$node, $form_state) {
      // nodetype2 form elements go here
    
      return $form;
    }
    
    function mymodule_nodetype1_load($node) {
      $additions = new stdClass();
    
      drupal_set_message('mymodule_nodetype1_load invoked');
    
      return $additions;
    }
    
    function mymodule_nodetype2_load($node) {
      $additions = new stdClass();
    
      drupal_set_message('mymodule_nodetype2_load invoked');
    
      return $additions;
    }
    

    If you’re not reseting your environment after changes to your module, you might be running into caching issues. You should test your code in a sandbox environment that can be reset to a clean Drupal installation to ensure you’re not focusing on old cruft from previous, incorrect node implementations.

    Additionally, you should only be using hook_nodeapi() if you are trying to act on content types that are not defined by your module. Your content types should be using the node hooks (hook_load(), hook_view(), etc.).

    Finally, it may be the case that you’re using the wrong hooks because you’re expecting them to fire in places they are not designed to. If you’ve gone through everything above, please update your post with the functionality you’re expecting to achieve and where you expect the hook to fire.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Drupal 6.x I have this module that manages four different content types. For that
I have a multi module web project. Four modules of the project are packaged
If you have: module A class B end end You can find B and
I have a module A: module A extend self attr_accessor :two, :four ONE =
I have an android application which contains four modules(I mean four apk's).Each module has
I have a four WAR files which are modules of application. How I can
I have module application. When I run it, the main window of that app
I have module that implements custom content type via NodeAPI hooks ( hook_insert ,
I have a module where a global environment (defining certain constraints such as neighbor
I have a module Namespace/Search, which was installed when I got here. I took

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.