I am trying to fetch the contact entity in a rule which triggers when a specific tag is added to that contact. I seem to be able to load and fetch the Drupal user for the contact but not the actual contact entity itself.

Is there a way for me to fetch the contact entity when a certain tag is added?

I want to fetch the contact entity so I can then delete it, using entity delete action in rules.

Ultimately I am using Webform for this which will add the tag which triggers the rule.

I know this sounds a bit dangerous but I hope to put some safeguards in place to prevent anyone with access to the webform deleting any contacts!

EDIT to Clarify:

I am trying to build the ability to delete a contact in CiviCRM using a webform in Drupal.

The way I wanted to do it, was that a CiviCRM contact with a Drupal user account logs into Drupal where they can see a list of all employees for the same organisation that they are employed by (I have done this part). I then want to give the logged in contact the ability to delete other employees of the organisation that they can see listed.

I have already managed to give logged in users the ability to create new contacts for their organisation with an option to create a Drupal account for the new contact as well.

I added the ability for logged in users to create new contacts, as well as a Drupal account, by following the very clear and helpful steps given in How can I create a Drupal user when someone submits a CiviCRM-Webform?

This method above, involved adding a tag to a contact which then triggers the add Drupal account rule. I was thinking to use the same method of adding a tag to a contact to trigger the delete contact rule. however, I can't seem to fetch the contact as an entity within the rule in order to delete the entity.

I am using Drupal 7.58 with CiviCRM 4.7.28.

  • Can you give a little more background? I assume you are using Drupal as CMS? What version of Drupal and what version of CiviCRM? What do you want to achieve functionally? It will help us to provide you with better answers. Commented May 2, 2018 at 14:29
  • @ErikH - I have added in some background information to clarify the question.
    – Ben
    Commented May 2, 2018 at 15:26
  • hi - as the author of that original blog i am interested to see how you get on. yes this sounds doable but am unclear if you are wanting to delete both the Contact, and the User if there is one connected to the Contact (which may require 2 separate actions in the right order)
    – petednz - fuzion
    Commented May 2, 2018 at 19:36
  • Hi Pete, thank you for your very helpful blog on this subject. If the contact has a Drupal account as well, then yes, I would want to delete the Drupal account and the Civi record. Not all contacts have a Drupal account as well though. I was thinking of using two seperate rules. One to delete the Drupal account and the other to delete the contact in Civi. I had got the rule for deleting the Drupal account working. It is just now to work out how to delete the contact in Civi...
    – Ben
    Commented May 3, 2018 at 11:31

2 Answers 2


You'll need the module CiviCRM Entity installed. https://drupal.org/project/civicrm_entity You will also need the Webform Rules module https://drupal.org/project/webform_rules

What you could do is add a checkbox for each contact that can be deleted to the webform, could just be a regular Webform component.

Then respond to the submission of that webform with a Rule.

In the submission data, there will be a value for the checkbox you add. If it is checked, then load the contact by cid, it will also be there in the submission data.

With CiviCRM Entity, CiviCRM entities like contact, become proper Drupal entity types, in this case civicrm_contact is the entity type. You can then use the regular "Delete an entity" Rules action.

Before you delete the contact, you will have to load it first. There is a Rules action, "Fetch entity by id", use this, and pass it the contact id you get from the webform submission data.


The other way would be to add the ability to a webform to set a contact to 'in trash' - assuming of course you really want them deleted rather than just have the relationship curtailed.


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.