0

Here is a code which can be pasted into devel/php (run php code) if the message template new_user_register exists with a user reference field called field_user_reference

This message should be sent when a new user register himself (But this has no link with my problem as the code can be run outside... I provide this information just to give some context)

$id=127;
$account=\Drupal\user\Entity\User::load($id);
$message=\Drupal\message\Entity\Message::create([
    'template' => 'new_user_register',
    'uid' => $id
]);
$message->set('field_user_reference', $account);
$message->save();

$subscribers = \Drupal::service('message_subscribe.subscribers');
$notify_options = [];
$subscribe_options = [
    'notify message owner' => TRUE,
    'notify blocked users'=>TRUE, //new user is blocked
    'entity access'=>FALSE, //new user don't have access (blocked)
    'uids' => [new \Drupal\message_subscribe\Subscribers\DeliveryCandidate(['subscribe_user'], ['email'], $id)],
];

$subscribers->sendMessage($account, $message,$notify_options,$subscribe_options);

Even if the template is translated, the user 127 will not receive the message in his preferred language but in the site default language.

Is it a bug or am I missing something?

1 Answer 1

0

I have made a path here: https://www.drupal.org/project/message_notify/issues/2965975#comment-13559090

Feel free to test it and report any problem

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.