postmark.install in Postmark 8
Same filename and directory in other branches
Install and uninstall routines.
File
postmark.installView source
<?php
/**
* @file
* Install and uninstall routines.
*/
use Drupal\Core\Link;
use Drupal\postmark\PostmarkHandler;
/**
* Implements hook_install().
*/
function postmark_install() {
$config = \Drupal::configFactory()
->getEditable('system.mail');
$mail_plugins = $config
->get('interface');
if (in_array('postmark', array_keys($mail_plugins))) {
return;
}
$mail_plugins['postmark'] = 'postmark';
$config
->set('interface', $mail_plugins)
->save();
}
/**
* Implements hook_install().
*/
function postmark_uninstall() {
$config = \Drupal::configFactory()
->getEditable('system.mail');
$mail_plugins = $config
->get('interface');
if (!in_array('postmark', array_keys($mail_plugins))) {
return;
}
unset($mail_plugins['postmark']);
$config
->set('interface', $mail_plugins)
->save();
}
/**
* Implements hook_requirements().
*/
function postmark_requirements($phase) {
$requirements = [];
if ($phase !== 'runtime') {
return $requirements;
}
$requirements = [
'postmark' => [
'title' => t('Postmark'),
],
];
if (PostmarkHandler::checkLibrary() === FALSE) {
$requirements['postmark']['description'] = t('The Postmark library has not been installed correctly.');
$requirements['postmark']['severity'] = REQUIREMENT_ERROR;
}
else {
$config = \Drupal::config('postmark.settings');
$key = $config
->get('postmark_api_key');
$signature = $config
->get('postmark_sender_signature');
if (PostmarkHandler::checkApiSettings($key, $signature) === FALSE) {
$requirements['postmark']['description'] = t('The Postmark library is installed but API settings are not configured. Please check your @link.', [
'@link' => Link::createFromRoute(t('settings'), 'postmark.settings')
->toString(),
]);
$requirements['postmark']['severity'] = REQUIREMENT_WARNING;
}
else {
$requirements['postmark']['description'] = t('The Postmark library is installed correctly. API settings are configured.');
$requirements['postmark']['severity'] = REQUIREMENT_OK;
}
}
return $requirements;
}
Functions
Name | Description |
---|---|
postmark_install | Implements hook_install(). |
postmark_requirements | Implements hook_requirements(). |
postmark_uninstall | Implements hook_install(). |