Skip to content

Commit 295dd06

Browse files
committed
Use site default language for notification messages
1 parent fc9bccc commit 295dd06

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ services:
3636
- PHP_MAX_EXECUTION_TIME=30
3737
- PHP_MEMORY_LIMIT=256M
3838
# Depending on the setup you may have to remove --read-envelope-from from msmtp (cf. https://marlam.de/msmtp/msmtp.html) or use SMTP to send mail
39-
- PHP_SENDMAIL_PATH=/usr/bin/msmtp --host=mail --port=1025 --read-recipients --read-envelope-from
39+
- PHP_SENDMAIL_PATH=/usr/bin/msmtp --host=mail --port=1025 --read-recipients
4040
- DOCKER_HOST_DOMAIN=${COMPOSE_DOMAIN}
4141
- COMPOSER_VERSION=2
4242
- PHP_IDE_CONFIG=serverName=localhost

web/profiles/custom/os2loop/modules/os2loop_mail_notifications/os2loop_mail_notifications.services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ services:
1414
- '@Drupal\os2loop_settings\Settings'
1515
- '@token'
1616
- '@plugin.manager.mail'
17+
- '@language.default'

web/profiles/custom/os2loop/modules/os2loop_mail_notifications/src/Helper/MailHelper.php

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Drupal\os2loop_mail_notifications\Helper;
44

5+
use Drupal\Core\Language\LanguageDefault;
56
use Drupal\Core\Mail\MailManagerInterface;
67
use Drupal\Core\Render\Markup;
78
use Drupal\Core\StringTranslation\StringTranslationTrait;
@@ -26,27 +27,16 @@ class MailHelper {
2627
*/
2728
private $config;
2829

29-
/**
30-
* The token.
31-
*
32-
* @var \Drupal\Core\Utility\Token
33-
*/
34-
private $token;
35-
36-
/**
37-
* The mail manager.
38-
*
39-
* @var \Drupal\Core\Mail\MailManagerInterface
40-
*/
41-
private $mailer;
42-
4330
/**
4431
* Helper constructor.
4532
*/
46-
public function __construct(Settings $settings, Token $token, MailManagerInterface $mailer) {
33+
public function __construct(
34+
Settings $settings,
35+
private readonly Token $token,
36+
private readonly MailManagerInterface $mailer,
37+
private readonly LanguageDefault $defaultLanguage
38+
) {
4739
$this->config = $settings->getConfig(SettingsForm::SETTINGS_NAME);
48-
$this->token = $token;
49-
$this->mailer = $mailer;
5040
}
5141

5242
/**
@@ -80,7 +70,7 @@ public function mail($key, &$message, $params) {
8070
* True if mail is sent.
8171
*/
8272
public function sendNotification(User $user, array $groupedMessages) {
83-
$langcode = $user->getPreferredLangcode();
73+
$langcode = $this->defaultLanguage->get()->getId();
8474

8575
$sections = [];
8676
foreach ($groupedMessages as $type => $messages) {
@@ -194,7 +184,12 @@ private function getMessageContent(Message $message, string $langCode): string {
194184

195185
// Append any revision message.
196186
if ($message->hasField('os2loop_revision_message') && !empty($message->get('os2loop_revision_message')->getValue())) {
197-
$content .= ' (' . $this->t('Revision message: @revision_message', ['@revision_message' => $message->get('os2loop_revision_message')->getString()]) . ')';
187+
$revisionMessage = $this->t(
188+
'Revision message: @revision_message',
189+
['@revision_message' => $message->get('os2loop_revision_message')->getString()],
190+
['langcode' => $langCode]
191+
);
192+
$content .= ' (' . $revisionMessage . ')';
198193
}
199194

200195
return $content;

0 commit comments

Comments
 (0)