Score:-1

Rules Custom Field

id flag

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 ?

fr flag
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.
fr flag
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.
Score:0
fr flag

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.

Monster971 avatar
id flag
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?
fr flag
If it helped please accept the answer! See https://stackoverflow.com/help/someone-answers
fr flag
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).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.