swiftmailer.install in Swift Mailer 8
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();
}
}
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. |