Skip to content
Snippets Groups Projects
Commit 9ffe4287 authored by Joshua Sedler's avatar Joshua Sedler :cartwheel_tone2: Committed by Julian Pustkuchen
Browse files

Issue #3501968 by anybody, grevil: Implement mail translation (by user preferred language)

parent 4f1f1cf4
No related branches found
Tags 1.0.0-rc1
1 merge request!6Issue #3501968: Implement mail translation (by user preferred language)
Pipeline #407502 passed with warnings
......@@ -146,7 +146,7 @@ final class SettingsForm extends ConfigFormBase {
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => $this->t('Final action'),
'#description' => $this->t('The final action is taken after all escalation steps were executed for a user, but '),
'#description' => $this->t('The final action is taken after all escalation steps were executed for a user without login.'),
'#states' => [
'visible' => [
':input[name="enabled"]' => ['checked' => TRUE],
......
......@@ -6,7 +6,7 @@ namespace Drupal\user_registration_reminder;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\Utility\Html;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\configFactoryInterface;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
......@@ -45,7 +45,7 @@ class Manager {
* Constructs a Manager object.
*/
public function __construct(
protected readonly ConfigFactoryInterface $configFactory,
protected readonly configFactoryInterface $configFactory,
protected readonly EntityTypeManagerInterface $entityTypeManager,
protected readonly MailManagerInterface $mailManager,
protected readonly UserDataInterface $userData,
......@@ -54,7 +54,6 @@ class Manager {
protected readonly Token $token,
protected readonly TimeInterface $timeService,
) {
$this->config = $configFactory->get('user_registration_reminder.settings');
$this->logger = $loggerChannelFactory->get('user_registration_reminder');
}
......@@ -62,7 +61,7 @@ class Manager {
* Runs the registration reminder check and processing.
*/
public function runRegistrationReminder(): void {
if (!$this->config->get('enabled')) {
if (!$this->configFactory->get('user_registration_reminder.settings')->get('enabled')) {
return;
}
$inactiveRegistrationUsers = $this->getInactiveRegistrationUsers();
......@@ -112,7 +111,7 @@ class Manager {
*/
protected function getFinalEscalationStepCount(): int {
$i = 0;
$reminderEscalations = $this->config->get("reminder_escalations");
$reminderEscalations = $this->configFactory->get('user_registration_reminder.settings')->get("reminder_escalations");
foreach ($reminderEscalations as $reminderEscalation) {
if ($reminderEscalation['delay'] > 0) {
$i++;
......@@ -133,7 +132,7 @@ class Manager {
* The escalation step configuration or NULL if not existing.
*/
protected function getEscalationStepConfig(int $escalationStep): ?array {
return $this->config->get("reminder_escalations.{$escalationStep}") ?? NULL;
return $this->configFactory->get('user_registration_reminder.settings')->get("reminder_escalations.{$escalationStep}") ?? NULL;
}
/**
......@@ -146,7 +145,7 @@ class Manager {
* The final action delay after the last escalation step.
*/
protected function getFinalActionDelay(): int {
return $this->config->get('final_action.delay') ?? 0;
return $this->configFactory->get('user_registration_reminder.settings')->get('final_action.delay') ?? 0;
}
/**
......@@ -159,7 +158,7 @@ class Manager {
* The final action delay after the last escalation step.
*/
protected function getFinalActionAction(): string {
return $this->config->get('final_action.action') ?? 'none';
return $this->configFactory->get('user_registration_reminder.settings')->get('final_action.action') ?? 'none';
}
/**
......@@ -172,7 +171,7 @@ class Manager {
* The first escalation timestamp to compare user creation against.
*/
protected function getFirstEscalationTimestamp(): int {
$delay = $this->config->get('reminder_escalations.0.delay');
$delay = $this->configFactory->get('user_registration_reminder.settings')->get('reminder_escalations.0.delay');
$time = $this->timeService->getRequestTime();
return $time - $delay;
}
......@@ -223,16 +222,23 @@ class Manager {
*/
protected function sendReminderEmail(UserDecorator $inactiveRegistrationUser): bool {
$user = $inactiveRegistrationUser->getUser();
$email = $user->getEmail();
$userLangcode = $user->getPreferredLangcode();
$userLanguage = $this->languageManager->getLanguage($userLangcode);
$original_language = $this->languageManager->getConfigOverrideLanguage();
// Temporarily set the user's language as the config override language,
// So we can get the email subject / body in the user's language:
$this->languageManager->setConfigOverrideLanguage($userLanguage);
$escalationStep = $inactiveRegistrationUser->getRecentEscalationStep();
// @todo: We need to get the config in the users language!
$escalationStepConfig = $this->getEscalationStepConfig($escalationStep);
// Reset the config override language:
$this->languageManager->setConfigOverrideLanguage($original_language);
$subject = $escalationStepConfig['email_subject'];
$body = $escalationStepConfig['email_body'];
$tokenValues = [
'user' => $user,
];
$token_options = ['langcode' => $user->getPreferredLangcode(), 'callback' => 'user_mail_tokens', 'clear' => TRUE];
$token_options = ['langcode' => $userLangcode, 'callback' => 'user_mail_tokens', 'clear' => TRUE];
$subject = $this->token->replace($subject, $tokenValues, $token_options);
$subject = Html::decodeEntities(strip_tags($subject));
$body = $this->token->replace($body, $tokenValues, $token_options);
......@@ -241,14 +247,15 @@ class Manager {
'subject' => $subject,
'body' => $body,
];
if ($emailBcc = $this->config->get("email_bcc")) {
if ($emailBcc = $this->configFactory->get('user_registration_reminder.settings')->get("email_bcc")) {
$params['headers']['Bcc'] = $emailBcc;
}
$email = $user->getEmail();
return $this->mailManager->mail(
'user_registration_reminder',
'user_registration_reminder',
$email,
$user->getPreferredLangcode(),
$userLangcode,
$params,
)['result'] ?? TRUE;
}
......
......@@ -411,7 +411,7 @@ final class UserRegistrationReminderKernelTest extends KernelTestBase {
$user_storage->resetCache([$user->id()]);
$user = $user_storage->load($user->id());
// @todo: Find out why the user still exists here!
// @todo Find out why the user still exists here!
// $this->assertEmpty($user);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment