// Generate tokens with interface language.
$link = Url::
fromRoute('user.page',
[],
['absolute' => TRUE
])->
toString();
foreach ($tests as $input =>
$expected) { $output =
$token_service->
replace($input,
['user' =>
$account],
['langcode' =>
$language_interface->
getId(), 'callback' => 'user_mail_tokens', 'clear' => TRUE
]);
$this->
assertStringStartsWith($link,
$output, 'Generated URL is in interface language.'
);
} // Generate tokens with the user's preferred language.
$account->preferred_langcode = 'de';
$account->
save();
$link = Url::
fromRoute('user.page',
[],
['language' => \Drupal::
languageManager()->
getLanguage($account->
getPreferredLangcode()), 'absolute' => TRUE
])->
toString();
foreach ($tests as $input =>
$expected) { $output =
$token_service->
replace($input,
['user' =>
$account],
['callback' => 'user_mail_tokens', 'clear' => TRUE
]);
$this->
assertStringStartsWith($link,
$output, "Generated URL is in the user's preferred language."
);
} // Generate tokens with one specific language.
$link = Url::
fromRoute('user.page',
[],
['language' => \Drupal::
languageManager()->
getLanguage('de'
), 'absolute' => TRUE
])->
toString();
foreach ($tests as $input =>
$expected) { foreach ([$user1,
$user2] as $account) { $output =
$token_service->
replace($input,
['user' =>
$account],
['langcode' => 'de', 'callback' => 'user_mail_tokens', 'clear' => TRUE
]);
$this->
assertStringStartsWith($link,
$output, "Generated URL in the requested language."
);
}