2

I created a new action on a new node being created, it shows up in my triggers and the action gets triggered. Works so far. Problem is trying to add additional functionality using some submitted field values. As of now, all its doing is logging in Watchdog. My goal is to be able to set a flag on the node based on certain values.

------------------------------------------------------------------

/**
 *  Implementation of hook_action_info().
 */

function my_custom_action_info() {
  return array(
    'my_custom_action' => array(
  'type' => 'node',
  'bundles' => array('article'),
  'label' => t('Check article for stuff'),
  'configurable' => FALSE,
  'triggers' => array('node_insert'),
    ),
  );
}

function my_custom_action($node) {
    $myvar = $node->nid;
    my_custom($myvar);
}   

function my_custom($myvar) {
    watchdog('Test', 'My Custom Variable: ' . $myvar);
}

--------------------------------------------------------------------------

If I set the variable to an integer or text, it works. But how to get any value from the submitted node? Eventually I'd like to get a value from a specific field, but for now just testing with the Node ID and can't seem to get it.

The error I'm getting is : "Notice: Trying to get property of non-object in my_custom_action() ... "

This part: $myvar = $node->nid;

2
  • Just a note but you might find it easier to use the Rules module instead. May 1, 2014 at 7:21
  • @David Rules is an option that I looked into but couldn't find a way to do what I needed -> take the value of a field from the new node, and compare it with every other node in the db. All I want to do is flag the new node if that field value is already in the db.
    – droopie
    May 1, 2014 at 13:58

1 Answer 1

0

yeah,

for some reason, my variable needed to be initiated first.

$myvar = 0;
$myvar = $node->nid;

that's it. works now. Problem/solution applies for Drupal 6 or 7.

Your Answer

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

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