function _social_core_set_default_email_logo_for_socialblue in Open Social 10.3.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_core/social_core.module \_social_core_set_default_email_logo_for_socialblue()
- 10.0.x modules/social_features/social_core/social_core.module \_social_core_set_default_email_logo_for_socialblue()
- 10.1.x modules/social_features/social_core/social_core.module \_social_core_set_default_email_logo_for_socialblue()
- 10.2.x modules/social_features/social_core/social_core.module \_social_core_set_default_email_logo_for_socialblue()
Function to set default email logo if not set already for OS.
2 calls to _social_core_set_default_email_logo_for_socialblue()
- social_core_install in modules/
social_features/ social_core/ social_core.install - Implements hook_install().
- social_core_update_8906 in modules/
social_features/ social_core/ social_core.install - Sets the Default E-mail logo to the rebranded version, if possible.
File
- modules/
social_features/ social_core/ social_core.module, line 1045 - The Social core module.
Code
function _social_core_set_default_email_logo_for_socialblue() {
// Only when socialblue is default we continue.
if (\Drupal::configFactory()
->get('system.theme')
->get('default') === 'socialblue') {
$logo = theme_get_setting('logo.url', 'socialblue');
$basetheme_url = drupal_get_path('theme', 'socialblue');
// Only if the theme setting for the logo, is still the socialblue
// default logo, we can update our default logo.
// If someone changed it to their own branding, let's not update it
// because that would create regression.
// that will be /profile/contrib/social/themes/socialblue/logo.svg.
if (!empty($basetheme_url) && $logo === DIRECTORY_SEPARATOR . $basetheme_url . DIRECTORY_SEPARATOR . 'logo.svg') {
// Add default image.
$config_factory = \Drupal::configFactory();
// Lets get the email logo settings.
$socialblue_settings = $config_factory
->getEditable('socialblue.settings');
$default_image = $socialblue_settings
->get('email_logo');
// Only if there is no default image, or if its the same as the
// socialblue logo we can continue.
if (empty($default_image) || $default_image === $basetheme_url . DIRECTORY_SEPARATOR . 'logo.svg') {
$file_system = \Drupal::service('file_system');
$uri = $file_system
->copy($basetheme_url . DIRECTORY_SEPARATOR . 'logo_email.png', 'public://logo_email.png', FileSystemInterface::EXISTS_REPLACE);
$media = File::create([
'uri' => $uri,
]);
$media
->setPermanent();
$media
->save();
$default_image[0] = $media
->id();
// We just save the file id.
$socialblue_settings
->set('email_logo', $default_image)
->save();
}
}
}
}