Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
For the moment I have a rule that has the "After updating an existing user account" event. In the conditions it is going to check if a certain field value is changed (using the account and account-unchanged data values), if so it will send an email and show a message.
But I also update users through cron and I only want to trigger this rule when the user edit form has been submitted.
Is that possible? I couldn't figure out how to do this...
Comments
Comment #1
RedEight CreditAttribution: RedEight at 95Visual commentedI am also trying to figure this out myself. My current thought is that there might be a way to check the url to determine if it was updated via the user edit page... But I'm at a loss as to how this would be done. Does anyone know of a rule condition that checks that?
Comment #2
saurabh.dhariwal CreditAttribution: saurabh.dhariwal at AddWeb Solution Pvt. Ltd. commentedPlease follow the below steps for your purpose:
Step 1 : Alter user edit with custom module.
Step 2 : Create custom rule event
Step 3 : Your rule conditions and actions set for this custom rule event.
Now, user update his profile your custom rule event will be fire and your action will execute with your rule.
Let me know if you face any query/concern regarding this.
Thanks!
Comment #3
RedEight CreditAttribution: RedEight at 95Visual commentedsaurabh.dhariwal, unfortunately that won't work for either of our use cases. Mainly because that will fire anytime the user_save() method is called on a user object that already exists. We want this to only occur if the user_save() operation was the result of a user edit form submission. I haven't been able to find a way of checking what called the user_save().
Comment #4
RedEight CreditAttribution: RedEight at 95Visual commentedI think I was able to figure this out. I implemented a form alter for the user edit form that adds a submit callback to the front of the submit callback list. I use the callback to check if the form was submitted via the "Save" button and set a 'flag' variable if it was (that way we know they are trying to update an existing user). I then implemented a variation of saurabh.dhariwal's "HOOK_user_update" that triggers our custom rules event if that variable was set.
Here's the code
And in YOUR_MODULE.rules.inc
Once you have that implemented, a new event will appear in the rules ui. Select that event and it works exactly the same as "After updating an existing user account" but it only fires when the user is manually saved via the form_user_profile form. Calls to user_save() from anywhere else will not fire the event.
Thank you saurabh.dhariwal for starting me on the right path toward a working rule event. =]
Comment #5
jelo CreditAttribution: jelo commentedI linked these issues https://www.drupal.org/node/2780389 because my use case is exactly the same. I do a programmatic update on login which triggers my rule (which it should not). However, I cannot prevent it from happening right now, but hope to stop the condition to fail by introducing a new condition to check if an object exists. That would allow you to not trigger your rule if the account-unchanged object does not exist (which is the case when user_save fires without user edit previously)...
Comment #6
TR CreditAttribution: TR commented#4 provides a solution to the original question.
The post in #5 has its own open issue, so we don't need to keep this one open as well.