I am developing a Drupal site, where the administrator creates user accounts. Indeed for this site the administrator creates user accounts, he fills in the fields with the strict minimum (Last name, First name, Mail).

When the user logs in, I would like the site to force him to fill in the remaining fields of the profile.

For this I wanted to use the Rules module, with:

  • Event: User has logged in
  • Condition: Data value is empty: Custom Field
  • Action: Page redirect (user/[account: uid]/edit)

The problem I am having is that I cannot access my customs fields in the data selector.

Anyone know how to access my customs fields in Rules ?

  • Note: A text description of how you configured your Rule is inadequate because in most cases it leaves off vital information. One specific thing missing is whether the value was entered in the data selector or by direct input - there's a HUGE difference between 'node' entered in the data selector and 'node' entered in direct input. Please in the future post an export of your Rule when asking a question or reporting a problem - the export has the complete information needed to reproduce your issue. – anonymous Jun 6 at 18:00
  • Rules in Drupal 8 does not use token module tokens. Instead, you need to use Twig syntax. In your case, the redirect destination should be entered as '/user/{{ account.uid.value }}/edit' using direct input. – anonymous Jun 6 at 18:00

The event 'User has logged in' puts into context the user entity for the user who has just logged in. The user entity by itself has no fields. The user entity with added fields is known as a bundle.

To expose the fields of the bundle to Rules you need to use the 'Entity is of bundle' condition. This condition takes three inputs:

  1. The specific entity you are checking. In your use case this should be the 'account' variable selected using the data selector.
  2. The entity type. This should be the machine name of the entity type selected in 1), which in your case is 'user', entered with direct input.
  3. The machine name of the bundle. Again, this will be 'user', entered with direct input.

Any conditions or actions added after this 'Entity is of bundle' condition will now have access to custom user fields.

The above steps are needed to expose the fields of any bundle to Rules - this is not just for the 'user' entity.

  • Thanks bro, it's worked ! Would you have a way so that the user does not have access to any other page until the fields are filled in? – Monster971 Jun 6 at 18:48
  • If it helped please accept the answer! See stackoverflow.com/help/someone-answers – anonymous Jun 6 at 20:24
  • To prevent access to other pages, I would suggest assigning a role to users that have fully-completed profiles. All users without that role can be redirected to the profile page when they log in, and can be prevented from accessing content or anything else by setting permissions on the "authenticated user" role (which is the default role). – anonymous Jun 6 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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