function social_swiftmail_preprocess_swiftmailer in Open Social 8.8
Same name and namespace in other branches
- 8.9 modules/social_features/social_swiftmail/social_swiftmail.module \social_swiftmail_preprocess_swiftmailer()
- 8 modules/social_features/social_swiftmail/social_swiftmail.module \social_swiftmail_preprocess_swiftmailer()
- 8.2 modules/social_features/social_swiftmail/social_swiftmail.module \social_swiftmail_preprocess_swiftmailer()
- 8.3 modules/social_features/social_swiftmail/social_swiftmail.module \social_swiftmail_preprocess_swiftmailer()
- 8.4 modules/social_features/social_swiftmail/social_swiftmail.module \social_swiftmail_preprocess_swiftmailer()
- 8.5 modules/social_features/social_swiftmail/social_swiftmail.module \social_swiftmail_preprocess_swiftmailer()
- 8.6 modules/social_features/social_swiftmail/social_swiftmail.module \social_swiftmail_preprocess_swiftmailer()
- 8.7 modules/social_features/social_swiftmail/social_swiftmail.module \social_swiftmail_preprocess_swiftmailer()
- 10.3.x modules/social_features/social_swiftmail/social_swiftmail.module \social_swiftmail_preprocess_swiftmailer()
- 10.0.x modules/social_features/social_swiftmail/social_swiftmail.module \social_swiftmail_preprocess_swiftmailer()
- 10.1.x modules/social_features/social_swiftmail/social_swiftmail.module \social_swiftmail_preprocess_swiftmailer()
- 10.2.x modules/social_features/social_swiftmail/social_swiftmail.module \social_swiftmail_preprocess_swiftmailer()
Preprocess swift template.
File
- modules/
social_features/ social_swiftmail/ social_swiftmail.module, line 15 - Module file for Social Swiftmailer.
Code
function social_swiftmail_preprocess_swiftmailer(array &$variables) {
// Load default theme (not active).
$theme_id = \Drupal::config('system.theme')
->get('default');
// Need to check this, since otherwise site-install will fail.
if (\Drupal::service('module_handler')
->moduleExists('color')) {
// Load the colors.
$colors = color_get_palette($theme_id);
}
// Set variables from theme.
$logo = social_swiftmail_get_logo($theme_id);
$primary = $colors['brand-primary'];
$secondary = $colors['brand-secondary'];
$accent = $colors['brand-accent'];
$link = $colors['brand-link'];
$border_radius = Xss::filter(theme_get_setting('border_radius', $theme_id));
// Add variables to send to the html template.
$variables['logo'] = $logo;
$variables['primary'] = $primary;
$variables['secondary'] = $secondary;
$variables['accent'] = $accent;
$variables['link'] = $link;
$variables['border_radius'] = $border_radius;
// Check if custom e-mail setting for branding removal is enabled.
$social_swiftmail_config = \Drupal::config('social_swiftmail.settings');
if ($social_swiftmail_config
->get('remove_open_social_branding') === TRUE) {
$site_config = \Drupal::config('system.site');
// When branding should be removed, check if the default site settings are
// set and override variables.
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('Open Social');
$variables['site_slogan'] = '"' . t('Make your people bloom') . '"';
}
// Check if a custom e-mail header is set and apply the configuration
// to the render array.
if (($header_config = $social_swiftmail_config
->get('template_header')) && (!empty($header_config['value']) && !empty($header_config['format']))) {
$header_markup = [
'#type' => 'processed_text',
'#text' => $header_config['value'],
'#format' => $header_config['format'],
];
$variables['header'] = \Drupal::service('renderer')
->renderRoot($header_markup);
}
// Check if a custom e-mail footer is set and apply the configuration
// to the render array.
if (($footer_config = $social_swiftmail_config
->get('template_footer')) && (!empty($footer_config['value']) && !empty($footer_config['format']))) {
$footer_markup = [
'#type' => 'processed_text',
'#text' => $footer_config['value'],
'#format' => $footer_config['format'],
];
$variables['footer'] = \Drupal::service('renderer')
->renderRoot($footer_markup);
}
$user = FALSE;
$message =& $variables['message'];
if (!empty($message['to'])) {
$user = user_load_by_mail($message['to']);
}
// Try to add a heading message.
if ($user || !empty($message['params']['context']['display_name'])) {
$options = [
'langcode' => $message['langcode'],
];
if ($user) {
$display_name = $user
->getDisplayName();
}
else {
$display_name = $message['params']['context']['display_name'];
}
$replace = [
'@display_name' => $display_name,
];
$variables['heading'] = t('Hi <strong>@display_name</strong>', $replace, $options);
}
}