开发者

Drupal Insert Hook Fails

I have an insert hook that catches nodes whenever the user adds a node. So here's my 开发者_如何学Pythoncode:

function blah_insert($node){
     $record = array(
            'nid' => (int) $node->nid
     );
     drupal_write_record('table_name', $record);
}

schema::

table_name(
     nid     int primary key not null
)

Performing a check on the return value of drupal_write_record results in FALSE. db_query doesn't work either. var_dump confirms that all the fields are where they're supposed to be.

The nodes are properly being inserted into the node tables but not the table that is defined by the schema in my install file (not written like the schema that I have above of course - nid is defined as an int and all other relevant fields).

Does anyone have any idea as to what's going on?


  1. Make sure your module is installed and enabled
  2. Make sure your module name is definitely named blah (or whatever you're putting before _insert
  3. Make sure that you're using the right hook...if your module is not responsible for defining a content type (i.e. a 'node' module) then you're using the wrong one. From the docs of hook_insert: "This hook is invoked only on the module that defines the node's content type". It may be that you're looking for hook_node_insert() instead, which responds to the insertion of a node of any type.
  4. When you implement any hooks in your module make sure you clear caches afterwards, depending on what version of Drupal you're using these implementations may be cached for quicker access and won't be picked up until that cache is cleared.
  5. Check that your custom table actually exists in the database! If not grab the devel module, install it and visit /devel/reinstall where you can invoke a full re-install of your module.

Once you've checked those if is still doesn't work it's symptomatic of a larger problem with your Drupal installation...if your schema is as you've said it is above then there's no reason drupal_write_record() wouldn't work if the function is indeed being run.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜