Synchronization of Drupal Users/Roles & CiviCRM Contacts/Groups

webtomme's picture

In CiviCRM I have following categories of individuals that is relevant to permissions they would have in the system:
- manager
- team lead
- sales
- customer

Each of these individuals are belonging to one and only one country, and each country has one and only one manager.

1: Custom ACL

  • A user logged in as a manager can create contacts of types team lead, sales and customer for the country he is responsible for.
  • A lead can create sales contacts only. And they will belong to the same country, he is operating in.
  • Sales and customers aren't allowed to create any contacts.
  • Managers, team leads, sales cannot see contacts from other countries.

2: I would like to synch whenever a CiviCRM contact is created it creates a Drupal user and assigns the roles: manager, team lead, sales, customer.

3 vice versa to #2. This way it seems to work fine.

I could auto assign roles that corresponds to CiviCRM groups.

Before I am jumping into API docs and try writing a custom module to solve both SYNC and ACL problem as above, I'd like to ask the more experienced CiviCRM developers first if there is already a solution provided by the community or an elegant configuration practice that I missed somewhere between the guide. It seems rules can't do this in a simple way from.


I believe the functionality

Slovak's picture

I believe the functionality you're looking for is already part of CiviCRM. It's called CiviGroup Roles Sync.

As mentioned, I could already

webtomme's picture

As mentioned, I could already auto assign users to roles that corresponds to the groups in CiviCRM.

My question still remains: contact -> groups -> user created and then assigned to roles via config!

Then the permission scenario as described.

I want to avoid any hard coding practices or duplicated module development, so a module has to be written if there isn't one yet.

I'm not aware of any

upperholme's picture

I'm not aware of any pre-existing module/extension that will create the Drupal user for you. I'm sure that if you were to develop something that could deliver the sort of functionality that you have described, there would be wider interest in this.

I too looked for this type of

awasson's picture

I too looked for this type of functionality at some point. There must be a hook available that creates new Drupal users somewhere in the core because if you create a new contact via a 'New Membership' contribution page, a Drupal user is created at the time the membership is created and everything is synched.

I think @awasson is on the

kreynen's picture

I think @awasson is on the right track, but what @Tom Tran described in the original post seems more complicated and not something that would lend itself to re-use. The fact that CiviCRM profile fields are added to the user_registration form isn't enough to do everything described, but it's a good place to start.

We've extended the CiviCRM Member and Group Sync for several Community Media clients with modules we've contributed back like CiviMember PLUS Roles Sync. I also wrote the patch that added the Manual Sync option to civicrm_group_roles as batch process that was added in CiviCRM 4.2.

I don't know of a way to do this out of the box with CiviCRM and any additional contrib modules or CiviCRM extensations so this is what I'd do...

Create a custom Drupal module that reuses the user_registration form by calling it from a different menu hook with different permissions. That allows a role to create new CiviCRM contacts and Drupal users without requiring the permissions to admin either. The CiviCRM fields added to the user_registration form can still be managed the way they normally are, but you'll be able to manipulate the values of the select lists with your custom module. So for something like...

manager can create contacts of types team lead, sales and customer for the country he is responsible for

The profile field itself would include all countries, but the options in the select list could be limited to only the value of the country the current user is the manager of. To achieve...

Managers, team leads, sales cannot see contacts from other countries.

If they only need to view contacts without editing, I would manage this with Views. Don't even give them permission to contacts in CiviCRM.

Another, more complicated option is to use a multi-domain configuration and create a new domain for each country when the manager is assigned. This can be very powerful, but requires a lot more configuration.

Good Luck!

Don't forget tomorrow is CiviDay. If there isn't already something planned in your city, there's still time to post an impromptu meetup at a coffee shop or bar and see if anyone shows up.

Thanks Kevin. The bottom line

webtomme's picture

Thanks Kevin. The bottom line for me is there need to be customized code developed. The actual problem is a bit more complex then the above simplified modeling but in the end it comes down to write your own logic as it's beyond common use case.

Another question: What can't Drupal do without major efforts, what CiviCRM could do just fine as is? I need to make judgements about time spent on learning curve (2 weeks?), very similar to the image on your top page.

CiviDay seems to be only big in US. In Vietnam people still using MS Access and what not to model there CRM processes.

What can't Drupal do without

kreynen's picture

What can't Drupal do without major efforts, what CiviCRM could do just fine as is?

It can. In addition, projects like RedHen, Core CRM, and Party are building Drupal native CRMs. We've done a lot of work w/ CiviCRM, SugarCRM, Convio and Saleforce. CiviCRM isn't always the best fit for an organization, but I can say with confidence that it is the best solution for the money for non-profits w/ a tech savvy staff member willing to read documentation.

I've already written a lot about the pros and cons of Drupal native CRMs, but the key issue are these:

  • Using Drupal as a framework to build both a CMS and CRM on requires configuration compromises in both.
  • While Drupal continues to move away from being a CMS "out of the box", the UI and workflows are still largely influenced by a publishing workflow. Users who aren't familiar with the "Drupal way" may find this very unintuitive.
  • Tying an organizations to Drupal core and contrib's upgrade cycle can be very limiting.
  • Product style distribution often have no or difficult upgrade paths between major Drupal releases (ie. OpenArtrium)

I prefer a CRM that can be disconnected from the CMS, but tightly integrated as well. Organizations with just basic brochureware sites can move between Drupal <-> Wordpress without impacting their CRM data or workflows.

In the community media space, we spend a lot of time training the people maintaining a web site's content, managing the Drupal "tools" they enable for their users (proposing a project/series, making reservations, submitting shows), managing the CiviCRM "tools" they enable for their users (managing contact info, paying membership dues, registering for classes). We created this graphic to help visualize the relationship between Drupal and CiviCRM.

It basically breaks down to the CiviCRM providing tools that allow staff to manage important features of the organizations, while Drupal enables some of these to be converted to self service workflows.

If you aren't planning to use many of thousands of CRM features CiviCRM has been developing, documenting, and support for years in a non-profit environment AND the upgrade path from D7 -> D8 isn't a concern, a Drupal native solution might be the best option.

On the ACL issue, could you

upperholme's picture

On the ACL issue, could you not achieve your goal using the existing CiviCRM ACL tool? I'm not an expert with Civi's ACL, but the documentation at implies that what you are after is achievable out of the box.

On the second point, about creating Drupal users, I would ask why you want to create Drupal user accounts. A different approach is to enable the contact to create their own Drupal user account, using a workflow along the lines of: A manager or team leader creates a contact in CiviCRM, and sends a standard email to the contact, inviting them to register on the site for a user account. If the contact is interested they will register (so this is also a useful indicator of the level of interest of the contact), and if the email address they register with is in the contact record the Drupal user account will be hooked up to the CiviCRM record previously created. The role can be applied via the Groups Role Synch module.

Just a thought.

@upperholme ACLs by group

kreynen's picture

@upperholme ACLs by group work great once the contacts are in a group for each country, but is there a way out of the box for each manager to only be able to add contacts to their county's group?

Mark Steven's picture

Like @slovak I really believed this functionality would be there, via CiviMember Roles Sync.

But it looks increasingly like I assumed wrong, and that's a major problem for me, and CiviCRM in general.

I appreciate the work that has gone into CiviCRM, but you can hardly call this a Drupal integration, when users created in CiviCRM cannot be synced to Drupal user accounts.

Someone tell me I'm missing something?!

It's not that they can't be

awasson's picture

It's not that they can't be synched...

1) If you create a Drupal user, a contact record will automatically be created in CiviCRM and the records will be synched.

2) If through a CiviCRM membership signup (contribution) page, you create a CiviCRM contact/member, a drupal user will be created and synched.

3) If you have a bunch of Drupal users and a bunch of CiviCRM contacts which are disconnected, you can synch them from the admin tools in CiviCRM.

The problem is that if you go into civiCRM and create contact records or do an import straight to civiCRM only, no Drupal user records will be created. The workaround is to use the user import tool in Drupal and the Contact import in CiviCRM and then synch contacts to users. This has worked well for me although I would prefer to have CiviCRM just create the users when it creates the contacts.

There's nothing stopping any one of us from building an extension to accomplish this and perhaps someone is currently working on it. I just checked gitHub and couldn't find anything but all the same, someone might be working on it.

  • If it is a full on (life/death) business requirement, then I would suggest getting in contact with the CiviCRM core developers and asking them if you can contract them to build the functionality for you and then build that into the budget of your project... Or you could contract one of the CiviCRM developers (

** I may work on something like this in the future but currently I have two other extensions on the front-burner and just don't have the time for that at this time.

Thanks... it's clear now anyway

Mark Steven's picture

Thanks for the reply - and apologies for my tone of frustration. It's just one of those things that seemed kind of obvious.

Anyway. I guess for the time being we'll have to rely on manual import, and a few rules of thumb for adding new contacts.

I've just been testing this and it does seem to work, though its a bit clunky.

I think it's perfectly reasonable

colemanw's picture

It's perfectly reasonable for CiviCRM to not create a user record for every contact record. Contacts are not users, they're more like nodes (pieces of content). While it's possible to sync nodes to users, I don't think anyone would fault Drupal for not doing this out of the box.

Yes and no

Mark Steven's picture

It needn't be the default behaviour, but it ought to be an available behaviour.

Take my scenario:

A membership organisation where individual membership is conferred to staff via the "employee of" relationship. Members with a status of "current" are entitled to access members-only content on the website.

And CiviCRM gets us 90% of the way there. CiviMember Roles Sync is all about making this work.

Which is why it's so puzzling to have this missing piece of the process.

90% sounds about right

colemanw's picture

90% is about as far as CiviCRM gets anyone anywhere out of the box. Fortunately the API is quite easy to use and it should only take you a tiny bit of custom code to finish the job.

Time to dust off the PHP

Mark Steven's picture

Time to dust off the PHP I guess :)

Re: Time to dust off the PHP I guess.

awasson's picture

Hey Mark,

Have you given any further thought to this topic? I'm interested in figuring out how we can make this work too.

I'm thinking that in CiviCRM + D7, after the new contact record has been created, we can grab all the pertinent information and use hook_user_insert() to create the new user. After that we call the civiCRM process that does a user to contacts synch.

Easier said than done but I think all the hooks are available, we just have to create an extension that connects all the bits.


Are you in?


It's your lucky day

Wow... That's much simpler

awasson's picture

Wow... That's much simpler than I anticipated. Thanks for posting that link!



slamorte's picture

What about the Feeds modules + an RSS (or some other souce feed) of the CiviCRM contact list? Since Feeds can create users from an input we just need a way to feed it CiviCRM contact info as it comes in.

I am not experienced enough to know if this will work. Can anyone comment?

I'm looking at this problem too. I have an organizing with a large and changing membership. Every week they are provided with a database dump of all current and new members, and that dump will get imported into CiviCRM. To save a lot of future hassles with new members creating new contacts because they registered at the site with a different email address, we want all new contacts, when imported, to generate matching Drupal users.

if you end up using the

petednz's picture

if you end up using the approach posted in blog above, you can just 'tag' contacts when you import them - job done.

pete davis : fuzion : connect + campaign + communicate

Has anyone considered using

24ma13wg's picture

Has anyone considered using hook_form_FORM_ID_alter to alter forms, like crm-quick-create, to add an extra submit handler function that does an insert into Drupal's user table at the same time 'Save' is clicked? I'm over simpifying, but in principle is this not more straight forward than the @petednz solution?

drupal role <-> civicrm contact type synch

HashKey's picture

Is it possible to automatically synchronise a drupal role with a specific contact type ?
It is possible with groups and membership but with contact type ???

You could probably do this

upperholme's picture

You could probably do this with Rules and the CiviCRM Entity module.


HashKey's picture

Hello and thank you upperholme,
I know how to check if a drupal user is created but I don't know how to create a civicrm contact with a specific contact type.
Any idea ?

Since it's possible with

colemanw's picture

Since it's possible with groups but not contact types, you could use a smart group based on contact type to bridge this gap.

not ok

HashKey's picture

Hello Coleman,
thank you for your answer but I need to add something :
In CiviCRM I created the custom groups with custom fields : group 1 for contact type 1 and group 2 for contact type 2.
When I see a contact type 1, I just want to see the custom group 1, I don't want to see the custom group 2.

That's why I work with custom groups, so that's why I need to synch drupal role with contact types.

Is my explanation better ?

Not clear what you are trying to achieve

upperholme's picture

You've got me confused. Not sure what you are aiming at.

clearing point

HashKey's picture

I will try to give a better explanation :
- I have drupal role 1 and drupal role 2
- I also created in civicrm contact type 1 and contact type 2

During registration on my drupal website, the user choose between drupal role 1 or Drupal role 2.

I need that : When the user choose drupal role 1 i need to associate civicrm contact type 1. And when he chooses drupal role 2, I need to associate him to civicrm contact type 2

Is it better ?
Maybe it could be possible with drupal rule and civicrm entity but I don't know how...


upperholme's picture

One possible approach: Use a CiviCRM integrated webform - with a conditional to route the user appropriately based on their choice of contact type - to handle the registration, collecting data as you need. In the webform you can have two fieldsets, optionally shown/hidden by the conditional, to specify the contact type as type 1 or type 2.

Use the recipe at to create the drupal user.

Use Coleman's idea of a smart group based on contact type, to drive the synch between contact type and role.

Creating users by using Rules

edvanleeuwen's picture

You can easily create users from contacts by using Rules/CiviCRM Entity. Please look here:


Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week