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, I am trying to code a custom rules action to toggle the mimemail preference for sending html/text email.
This is my custom rules action:
function mymodule_rules_action_toggle_mimemail_preference($account) {
// mimemail_user_presave() needs to be disabled for this to work.
$mimemail_preference = $account->data['mimemail_textonly'];
if ($mimemail_preference == 0) {
$account->data['mimemail_textonly'] = 1;
}
else {
$account->data['mimemail_textonly'] = 0;
}
user_save($account);
}
The issue I ran into is that Mimemail calls hook_user_presave(), which blocks this action from being evaluated:
function mimemail_user_presave(&$edit, $account, $category) {
$edit['data']['mimemail_textonly'] = isset($edit['mimemail_textonly']) ? $edit['mimemail_textonly'] : 0;
}
This is necessary to update the user profile, but how do I get around this in Rules?
Comments
Comment #1
ptmkenny CreditAttribution: ptmkenny commentedComment #2
ptmkenny CreditAttribution: ptmkenny commentedOk, I see now this is necessary to save the user profile. So I'm editing the original issue to update my question.
Comment #3
TR CreditAttribution: TR commentedThis issue is D7-specific, as user email preferences are handled in a completely different way in D8/D9.
It seems what you're trying to do is to ignore the user-selected preference and use the admin-selected preference instead, which IMO is just wrong. IF you are going to allow the user to select a preference, then respect that choice. If you don't want your users to choose, hook_form_alter() the user profile and disallow that choice. You can hardwire that choice to allow HTML emails for everyone, in which case the admin-selected preference will always be used.
Comment #4
TR CreditAttribution: TR commented