function varbase_email_preprocess_swiftmailer in Varbase Email 9.0.x
Same name and namespace in other branches
- 8.6 varbase_email.module \varbase_email_preprocess_swiftmailer()
Prepares variables for varbase_emails.html.twig templates.
Implements hook_preprocess_HOOK() for field templates.
File
- ./
varbase_email.module, line 33 - Contains varbase_email.module.
Code
function varbase_email_preprocess_swiftmailer(&$variables) {
$language = \Drupal::languageManager()
->getCurrentLanguage();
$theme_id = \Drupal::config('system.theme')
->get('default');
$site_config = \Drupal::config('system.site');
$request = \Drupal::request();
$host = $request
->getSchemeAndHttpHost();
$variables['dir'] = $language
->getDirection();
// Default we use the logo image.
if (theme_get_setting('email_logo_default', $theme_id)) {
$variables['logo'] = $host . theme_get_setting('logo.url', $theme_id);
}
else {
$fid = theme_get_setting('email_logo_upload', $theme_id);
if ($fid && is_array($fid) && count($fid)) {
$file = File::load($fid[0]);
if ($file) {
$url = $file
->createFileUrl();
$variables['logo'] = $url;
}
}
elseif (theme_get_setting('email_logo_path', $theme_id)) {
$uri = theme_get_setting('email_logo_path', $theme_id);
$scheme = StreamWrapperManager::getScheme($uri);
if ($scheme) {
$variables['logo'] = file_create_url($uri);
}
else {
$variables['logo'] = $host . file_create_url($uri);
}
}
else {
$variables['logo'] = $host . theme_get_setting('logo.url', $theme_id);
}
}
if ($site_config) {
$variables['site_link'] = TRUE;
$variables['site_name'] = $site_config
->get('name');
if ($site_config
->get('slogan')) {
$variables['site_slogan'] = $site_config
->get('slogan');
}
}
else {
$variables['site_name'] = t('Varbase');
$variables['site_slogan'] = '"' . t('The Ultimate Drupal 8 CMS Starter Kit') . '"';
}
if ($user = user_load_by_mail($variables['message']['to'])) {
$message = $variables['message'];
$options = [
'langcode' => $message['langcode'],
];
$replace = [
'%display_name' => $user
->getDisplayName(),
];
$variables['heading'] = t('Hi %display_name', $replace, $options);
}
}