开发者

Weird problem with hook_view drupal

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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜