Search code examples
phpdrupaldrupal-7

Get user email and node title for custom block


I am trying to create a custom "contact node author" block. I have the form created as well as the block. What I need to do is when the block shows I need to be able to pull the node title as well as the nodes authors email address, populate a few hidden form elements, validate it all and submit the form.

But I am stumped as to how to pull up the current $node and $user objects (depending on which page the block appears on) to be able to use $user->email and $node->title.

I realize there are other modules out there, but I don't want the overhead of using 5 other modules to basically pull an email and send a message via mail().

Thanks


Solution

  • 2 easy ways I know of.

    if ($node == menu_get_object()) {
      // $node available
    }
    

    OR

    if (arg(0) == 'node') {
      $nid = arg(1);
      if ($nid) {
        $node = node_load($nid);
      }
    }