You are here

function postmark_requirements in Postmark 8

Same name and namespace in other branches
  1. 7 postmark.install \postmark_requirements()

Implements hook_requirements().

File

./postmark.install, line 42
Install and uninstall routines.

Code

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;
}