2

I am creating a custom module for Drupal 7. I wanted to post the node that gets created of type "Article" to facebook wall so that user doesn't have to manually create a wall post.

For that I need to get a method (function) in drupal which gets called as soon as the nodes gets created, where I can put my Facebook API codes.

3 Answers 3

2

You are looking for hook_node_insert()

This is from API page:

Respond to creation of a new node.

This hook is invoked from node_save() after the database query that will insert the node into the node table is scheduled for execution, after the type-specific hook_insert() is invoked, and after field_attach_insert() is called.

function MyModule_node_insert($node) {

  if($node->type == 'article') {
    //your code here
    custom_func();
  }
}

function custom_func() {
  //your code goes here
}
0
0

Another way to achieve this goal is http://twitterfeed.com. It allows you to export RSS (generated by views) to several social networks, including Facebook.

0

In most cases

 hook_node_insert();

does the job. The hook_node_insert() is called before actual database write query so you cannot retrieve nid from that node. Another hook called after saving node is:

hook_node_postinsert();

Available after installing module

https://drupal.org/project/hook_post_action

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.