drupal-7drupal-rules

Rules action: add a node


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?


Solution

  • 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',
          ),
        ),
      );
    }