1

Is there a way of (when I add a user) to create a node with he as author?

And is it possible to write own actions?

Stephan Muller
  • 27,018
  • 16
  • 85
  • 126
Max Allan
  • 640
  • 5
  • 18

1 Answers1

1

Yes, and yes.

For the first one you'll need the Entity API module which will give you a new action called 'Create a new entity'. You can use this along with the event 'After saving a new user account' to create a new node with the newly created user as the author. I won't go into detail as it's pretty self-explanatory when you're going through the UI.

For the second, you need to implement hook_rules_action_info(). This example from the docs page contains all of the required, and some optional, properties to create an action:

function hook_rules_action_info() {
  return array(
    'mail_user' => array(
      'label' => t('Send a mail to a user'), 
      'parameter' => array(
        'user' => array(
          'type' => 'user',
          'label' => t('Recipient'),
        ),
      ), 
      'group' => t('System'), 
      'base' => 'rules_action_mail_user', 
      'callbacks' => array(
        'validate' => 'rules_action_custom_validation', 
        'help' => 'rules_mail_help',
      ),
    ),
  );
}
Clive
  • 36,918
  • 8
  • 87
  • 113
  • Yes it's possible to create a node as an action and writing actions is quite simple. Just have a look at the documentation and the rules.api.php file in the module directory. Entity API is not really a dependency to create a node programmatically. Just search for "programmatically create node" and you will find a ton of good code examples that will have to go in the action function. Example: http://www.group42.ca/creating_and_updating_nodes_programmatically_in_drupal_7 – mikewink Jun 15 '12 at 22:42