swiftmailer.install in Swift Mailer 8.2
Same filename and directory in other branches
Contains install and update functions for SwiftMailer.
File
swiftmailer.installView source
<?php
/**
* @file
* Contains install and update functions for SwiftMailer.
*/
/**
* Implements hook_requirements().
*/
function swiftmailer_requirements($phase) {
$requirements = [];
if ($phase == 'install') {
if (!class_exists('Swift_Mailer')) {
$requirements['swiftmailer_library'] = [
'description' => t('Swift Mailer requires the external Swift Mailer library. The recommended way of solving this dependency is using the <a href=":url">Composer Manager</a> module.', [
':url' => 'https://www.drupal.org/project/composer_manager',
]),
'severity' => REQUIREMENT_ERROR,
];
}
}
return $requirements;
}
/**
* Implements hook_install().
*/
function swiftmailer_install() {
$settings = Drupal::configFactory()
->getEditable('mailsystem.settings');
$settings
->set('modules.swiftmailer.none', [
'formatter' => 'swiftmailer',
'sender' => 'swiftmailer',
])
->save();
}
/**
* Set default filter_format for HTML emails with no HTML markup.
*/
function swiftmailer_update_8101() {
Drupal::configFactory()
->getEditable('swiftmailer.message')
->set('filter_format', 'plain_text')
->save();
}
/**
* Update username/password credentials configuration.
*/
function swiftmailer_update_8102() {
$config = Drupal::configFactory()
->getEditable('swiftmailer.transport');
if (empty($config
->get('smtp_credential_provider'))) {
$config
->set('smtp_credential_provider', 'swiftmailer');
$config
->set('smtp_credentials.swiftmailer.username', $config
->get('smtp_username'));
$config
->set('smtp_credentials.swiftmailer.password', $config
->get('smtp_password'));
$config
->clear('smtp_username');
$config
->clear('smtp_password');
$config
->save();
}
}
/**
* Set default transport to Sendmail.
*/
function swiftmailer_update_8103() {
$config = Drupal::configFactory()
->getEditable('swiftmailer.transport');
if ($config
->get('transport') == 'native') {
$config
->set('transport', SWIFTMAILER_TRANSPORT_SENDMAIL);
$config
->save();
}
}
/**
* Update message settings.
*/
function swiftmailer_update_8104() {
$config = Drupal::configFactory()
->getEditable('swiftmailer.message');
$content_type = $config
->get('respect_format') ? '' : $config
->get('format');
$config
->set('content_type', $content_type)
->set('text_format', $config
->get('filter_format'))
->set('generate_plain', $config
->get('convert_mode'))
->clear('format')
->clear('respect_format')
->clear('filter_format')
->clear('convert_mode')
->save();
}
Functions
Name | Description |
---|---|
swiftmailer_install | Implements hook_install(). |
swiftmailer_requirements | Implements hook_requirements(). |
swiftmailer_update_8101 | Set default filter_format for HTML emails with no HTML markup. |
swiftmailer_update_8102 | Update username/password credentials configuration. |
swiftmailer_update_8103 | Set default transport to Sendmail. |
swiftmailer_update_8104 | Update message settings. |