Using the Drupal Rules module, I'm trying to create a rule whereby when a user registers, a taxonomy vocabulary is created.

So far, I've done the following:

EVENT: After saving a new user account

ACTIONS: Create a new Entity, value Taxonomy vocabulary. I enter a name using tokens but it doesn't seem to accept tokens for the machine name. The machine name obviously has to be unique to each vocabulary.

Just to give you a bit more info, each member registering is a Tutor (needs to be the taxonomy vocabulary) and each Tutor will create multiple Students (taxonomy terms).

Can anyone help me with this please? I'm using Drupal 7. Thank you :)

1 Answer 1


I have checked the rules and I couldn't find a Data Selector for user name. But if you are fine with achieving the same using custom code then you can use the following code.

function YOURMODULENAME_user_insert(&$edit, $account, $category){
   $vocabulary = new stdClass();
   $vocabulary->name = $account->name;
   $vocabulary->machine_name = "tutor_".$account->uid;
   $vocabulary->hierarchy = 0;
  • Thanks for your reply. Can you tell me where I would put this code and I'll give it a go. I'm not familiar with adding code like this so any additional info I may need would be brilliant - thank you :) Jul 4, 2014 at 10:15
  • You have to write a custom module and place the code there. Here is a link explaining how to create a module.
    – msmani
    Jul 4, 2014 at 10:39

Your Answer

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

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