0

I am trying to publish a node onto facebook. Below is my code. In hook_nodeapi(), I have placed a dpm("test") but it isnt showing. I am assuming that this function is not called at all?

function fb_stream_ext_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  dpm("test");
  if ($op == 'insert' || $op == 'update') {
    if (isset($node->stream_publish) && $node->stream_publish) {
      $attachment = array(
        'name' => $node->title,
        'href' => url('node/' . $node->nid, array('absolute' => TRUE)),
        'description' => filter_xss($node->teaser, array()),
      );

      /*
        if ($picture = $GLOBALS['user']->picture) {
        $url = url($picture, array('absolute' => TRUE));
        $attachment['media'][] = array(
        'type' => 'image',
        'src' => $url,
        'href' => $url,
        );
        }
      */
      if ($logo_path = theme_get_setting('logo_path')) {
        $url = url($logo_path, array('absolute' => TRUE));
        //dpm($logo_path, "logo_path is $logo_path and url is $url");
        $attachment['media'][] = array(
          'type' => 'image',
          'src' => $url,
          'href' => $url,
        );
      }

      $user_message = t('Check out my latest post on !site...',
                        array('!site' => variable_get('site_name', t('my Drupal for Facebook powered site'))));
      $actions = array();
      $actions[] = array(
        'text' => t('Read More'),
        'href' => url('node/' . $node->nid, array('absolute' => TRUE)),
      );
      fb_stream_publish_dialog(array('message' => $user_message,
                                     'attachment' => $attachment,
                                     'action_links' => $actions,
                               ));
    }
  }

  // Another way to add like button, as part of a node.
  if ($op == 'view' && variable_get('fb_stream_ext_nodeapi_add_like', FALSE)) {
    $url = fb_scrub_urls(url('node/' . $node->nid, array('absolute' => TRUE)));
    $node->content['dff_like'] = array(
      '#value' => "<fb:like href={$url}></fb:like>",
      '#type' => 'markup',
      '#prefix' => '<div class="dff_like_wrapper">',
      '#suffix' => '</div>',
    );
  }
}

Any known solution for this?

  • Try placing your dpm("test"); inside if ($op == 'view'){ ... } and then check, if it shows up. – aerozeppelin Sep 4 '12 at 15:18
  • still nothing. When will this function be called? I read somewhere that hook_nodeapi doesnt work in drupal 7 – He Hui Sep 4 '12 at 15:20
  • can you write the hook for me... just getting confused with the other things in the parenthesis (&$node, $op, $a3 = NULL, $a4 = NULL) ... what goes in there is it just $node now? – Sun Rhythms Jan 21 '13 at 12:12
0

Sorry, there is no hook_nodeapi() for D7. In D7, there are seperate hooks for create, update, view and delete operations. You could use this Link as a reference. You could insert your dpm("test"); inside hook_view() to test it.

| improve this answer | |
  • if thats the case, i'm assuming drupalforfacebook is completely out of date? – He Hui Sep 4 '12 at 15:40
  • Why do you think so? – aerozeppelin Sep 4 '12 at 15:46
  • because the above function was copied directly from DrupalForFacebook, in order to post a node as a facebook stream – He Hui Sep 4 '12 at 15:51
0

I found the solution myself:

Yes, DrupalForFacebook is out of date. as Dave states here

hook_nodeapi() is a drupal 6 function, not a drupal 7 function.

The solution is simple: to find a hook function that can replace _nodeapi.

This function does the exact same thing as hook_nodeapi().

If one changes

yourHook_nodeapi

to

yourHook_node_presave($node)

problem is solved.

Thank you for all the help given.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.