0

I'm having a weird problem with hook_view. The problem is, hook_view isn't invoked unless hook_load returns invalid value such as empty variable. I don't know what causes this to happen and I'm at my wit's end. I'm very much appreciate your help. For what is worth, I have image attach module installed.

Drupal 6.x

UPDATE

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){
   $query = 'SELECT f1,f2,...,f10 FROM {tb1} INNER JOIN {tb2} ON {tb1}.vid = {tb2}.vid WHERE {tb1}.vid = %d';

   $result = db_query($query,$node->vid);

   return db_fetch_object($result);
}

function mymodule_nodetype1_view($node, $teaser = FALSE, $page = FALSE){
    $node = node_prepare($node, $teaser); // get it ready for display

    $f1 = check_markup($node->f1);
     ..............
    $f10 = check_markup($node->f10);

    // Add theme stuff here
    $node->content['mycontent'] = array(
       '#value' => theme('defaultskin', $f1,...,$f10),
       '#weight' => 1,
    ); 

    return $node;
}

function mymodule_theme(){
    return array(
        'defaultskin' => array(
            'template' => 'node-defaultskin',
            'arguments' => array(               
                'f1' => NULL,
                ......
                'f10' => NULL,
            ),
        ),
    );
}
3
  • Do you try to render the node?
    – tamasd
    Sep 11, 2010 at 16:45
  • Can you elaborate?Cuz I'm not sure what you mean. But, if you are asking if I view the content in node view, yes I do. hook_view isn't invoked in either view - teaser view, node view.
    – Andrew
    Sep 11, 2010 at 21:16
  • I've updated and posted the code. Kind of long though.
    – Andrew
    Sep 12, 2010 at 12:20

2 Answers 2

1

I found the culprit. Just in case somebody run into same problem I did, here's why - I named one field as "TYPE" and, when I retrieved recordset inside hook_load with drupal_fetch_object, I believe, the resulted object's member name "type" might have caused some naming conflict with drupal core member. As a result, this causes it to not invoke hook_view. After I renamed my field to something different, it works like charm. So, never name field as "Type". You guys might have knew that too but, due to my intention to make code easier to read, I renamed those fields to much simpler ones (f1,...f10). Sorry for the trouble. And thanks everyone for your effort.

cheers

0

This hook is meant for usage in a node module(so a module that itself creates a new node type), I assume you're using it for nodes defined by Drupal or CKK or another module, if so, use hook_nodeapi() instead with the view argument.

http://api.drupal.org/api/function/hook_nodeapi/6

1
  • Nope. I'm using hook_view for my own custom content created/defined inside my module. I've posted code for better evaluation.
    – Andrew
    Sep 12, 2010 at 12:21

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.