0

The operation should be as follows: Trigger an event after registering a new user.

  • test_rules_rules_event_info (example_rule_event) it's my event
  • test_rules_user_insert when a user is registered
  • test_rules_customFunction the function that is called by the rule

Therefore, when a user is registered, my event is triggered, and `test_rules_customFunction() is called by running the PHP code set by the Rules interface. When the user is created from the UI, this is done. When the user is programmatically created, this doesn't happen.

The code I am using is the following.

function test_rules_rules_event_info() {
  return array(
    'example_rule_event' => array(
      'label' => t('Regola test, quando un utente è registrato'),
      'module' => 'test_rules',
      'group' => 'test' ,
      'variables' => array(
        'current_user' => array('type' => 'user', 'label' => t('The current user.')),
      ),
    ),
  );
}
    
function test_rules_user_insert(&$edit, $account, $category) {
  watchdog("test_rules_user_insert", '<pre>' . print_r( $account, true) . '</pre>');
  rules_invoke_event('example_rule_event', $account);
}
    
function test_rules_customFunction($current_user){
  watchdog("test_rules_customFunction", '<pre>' . print_r( $current_user, true) . '</pre>');
  var_dump($current_user);
  exit;
}
4
  • Welcome to Drupal Answers! Are you sure test_rules_customFunction() has been associated to the right event? From what I can find googling, there isn't anything in the code that is wrong.
    – apaderno
    Commented Nov 16, 2020 at 14:24
  • Thanks for editing the question.
    – Leo
    Commented Nov 16, 2020 at 14:54
  • I have read that it could be an execution order problem, and that it would be solvable by the hook hook_module_implements_alter @kiamlaluno
    – Leo
    Commented Nov 16, 2020 at 14:55
  • This doesn't seem to have anything to do with Rules - if your hook isn't being run, then it has nothing to do with the code in your hook ... If hook_user_insert() isn't being called when you create a user programmatically, then that may be because you're not creating the user using the Drupal API?
    – anonymous
    Commented Nov 18, 2020 at 21:06

0

Your Answer

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

Browse other questions tagged or ask your own question.