social_swiftmail.module in Open Social 8.2
Same filename and directory in other branches
- 8.9 modules/social_features/social_swiftmail/social_swiftmail.module
- 8 modules/social_features/social_swiftmail/social_swiftmail.module
- 8.3 modules/social_features/social_swiftmail/social_swiftmail.module
- 8.4 modules/social_features/social_swiftmail/social_swiftmail.module
- 8.5 modules/social_features/social_swiftmail/social_swiftmail.module
- 8.6 modules/social_features/social_swiftmail/social_swiftmail.module
- 8.7 modules/social_features/social_swiftmail/social_swiftmail.module
- 8.8 modules/social_features/social_swiftmail/social_swiftmail.module
- 10.3.x modules/social_features/social_swiftmail/social_swiftmail.module
- 10.0.x modules/social_features/social_swiftmail/social_swiftmail.module
- 10.1.x modules/social_features/social_swiftmail/social_swiftmail.module
- 10.2.x modules/social_features/social_swiftmail/social_swiftmail.module
Module file for Social Swiftmailer.
File
modules/social_features/social_swiftmail/social_swiftmail.moduleView source
<?php
/**
* @file
* Module file for Social Swiftmailer.
*/
use Drupal\Component\Utility\Xss;
use Drupal\file\Entity\File;
/**
* Preprocess swift template.
*/
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;
$social_swiftmail_config = \Drupal::config('social_swiftmail.settings');
if ($social_swiftmail_config
->get('remove_open_social_branding') === 1) {
$site_config = \Drupal::config('system.site');
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') . '"';
}
// Try to add a heading message.
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);
}
}
/**
* Implements hook_mail_alter().
*/
function social_swiftmail_mail_alter(&$message) {
// Get the site settings.
$site_settings = \Drupal::config('system.site');
// If there is something set as 'from' sender, we append the site name.
if (isset($message['from'])) {
$message['from'] = $site_settings
->get('name') . ' <' . $message['from'] . '>';
}
else {
$message['from'] = $site_settings
->get('name') . ' <' . $site_settings
->get('mail') . '>';
}
}
/**
* Function the fetches the logo.
*/
function social_swiftmail_get_logo($theme_id) {
// Determine host.
$request = \Drupal::request();
$host = $request
->getSchemeAndHttpHost();
// Default we use the logo image.
$logo = $host . theme_get_setting('logo.url', $theme_id);
// It could be overridden here.
$email_logo = theme_get_setting('email_logo', $theme_id);
// Must be a non-empty array.
if (is_array($email_logo) && !empty($email_logo)) {
$file = File::load($email_logo[0]);
if ($file instanceof File) {
$logo = file_create_url($file
->getFileUri());
}
}
return $logo;
}
Functions
Name![]() |
Description |
---|---|
social_swiftmail_get_logo | Function the fetches the logo. |
social_swiftmail_mail_alter | Implements hook_mail_alter(). |
social_swiftmail_preprocess_swiftmailer | Preprocess swift template. |