You are here

function cloudflare_requirements in CloudFlare 8

Implements hook_requirements().

File

./cloudflare.install, line 13
Install, update, and uninstall functions for the CloudFlare module.

Code

function cloudflare_requirements($phase) {
  $requirements = [];
  if (!class_exists('\\CloudFlarePhpSdk\\ApiEndpoints\\ZoneApi')) {
    $requirements['cloudflare_library'] = [
      'title' => t('CloudFlare - Php Sdk'),
      'description' => t('CloudFlare requires the d8-contrib-modules/cloudflarephpsdk library.'),
      'severity' => REQUIREMENT_ERROR,
    ];
  }
  if ($phase == 'runtime') {
    $config = \Drupal::config('cloudflare.settings');
    $valid_credentials = $config
      ->get('valid_credentials') === TRUE;
    if (!$valid_credentials) {
      $link_to_settings = Url::fromRoute('cloudflare.admin_settings_form')
        ->toString();
      $message = t('Missing valid credentials for CloudFlare. Please go <a href="@link_to_settings">here</a> to set.', [
        '@link_to_settings' => $link_to_settings,
      ]);
      $requirements['cloudflare'] = [
        'title' => t('CloudFlare - Credentials'),
        'severity' => REQUIREMENT_ERROR,
        'description' => $message,
      ];
    }
    if (\Drupal::moduleHandler()
      ->moduleExists('cloudflare_zone_ui')) {
      \Drupal::service('module_installer')
        ->uninstall([
        'cloudflare_zone_ui',
      ]);
    }
  }
  return $requirements;
}