Hook_load / hook_view not called

I have a module with four declared node types. My problem: hook_load, hook_view is never called. I used drupal_set_message to find out if any hook was called. And I discovered hook_load, hook_view - no. Just to give you a clear picture, here is my hook_load structure

HERE UPDATED

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 do not know why it is not called. I wrote this code base in a Drupal module writing book and follow the instructions. I tried the sample code from this book and it works fine. Only my code does not work. Probably due to several node types in one module. Any help would be greatly appreciated.

+3
source share
2 answers

, hook_load() hook_view() : node hooks. , .

, , 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;
}

, hook_node_info() node. mymodule_nodetype1_load(), mymodule_nodetype2_view() ..


< node node, 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;
  }
}

mymodule_load_function() mymodule_load_function() , $node.


2

hook_load(), , , . ( nodetype1 node, "mymodule_nodetype1_load invoked" node): , , , .

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;
}

, . , reset, Drupal, , , node.

, hook_nodeapi(), , . node (hook_load(), hook_view() ..).

, , , , , . , , , , , .

+7

, . , , . - node hook_node_info , hook_form switch . , -

function mymodule_node_info(){
   return array(
      'nodetype1' => array(
         .....
         'module' => 'mymodule',
         .....
     ),
     'nodetype2' => array(
         ......
         'module' => 'mymodule',
         ......
     ),
         .......

    );

 }
function mymodule_form(&$node, $form_state){
switch($node->type){
    case 'nodetype1':
        return nodetype1_form();
    break;      

    case 'nodetype2':
        return nodetype2_form();
    break;
    .....

}
}

, hook_load. ! ( , , , ), , , . , drupal store form_id node hook_load. , , node, hook_load .

.

0

Source: https://habr.com/ru/post/1762119/


All Articles