You are here

function evercurrent_requirements in Evercurrent 8.2

Same name and namespace in other branches
  1. 8 evercurrent.install \evercurrent_requirements()
  2. 7.2 evercurrent.module \evercurrent_requirements()
  3. 7 evercurrent.module \evercurrent_requirements()

Implements hook_requirements().

Allow us to display current status in the site's status page.

File

./evercurrent.install, line 13
Drupal install file for RMH

Code

function evercurrent_requirements($phase) {
  $requirements = [];

  // We only do stuff at runtime.
  if ($phase !== 'runtime') {
    return $requirements;
  }
  $state = \Drupal::state();
  $config = \Drupal::config('evercurrent.admin_config');

  // Listening enabled?
  $listen = $config
    ->get('listen');
  $listen_on_text = t('The Evercurrent module is listening for a key to use.
   You should finish configuration on the server side, or turn the listening feature off
   in the settings.');
  $requirements['evercurrent_listen'] = [
    'title' => t('Evercurrent: Listening mode'),
    'value' => $listen ? t('Listening enabled') : t('Disabled'),
    'severity' => $listen ? REQUIREMENT_WARNING : REQUIREMENT_OK,
    'description' => $listen ? $listen_on_text : '',
  ];

  // Last run
  $updateHelper = \Drupal::service('evercurrent.update_helper');
  $requirements['evercurrent_last_run'] = [
    'title' => t('Evercurrent: Last successful run'),
    'value' => $updateHelper
      ->lastRun(),
    'severity' => REQUIREMENT_OK,
  ];

  // Drop last status to the panel
  $message = $state
    ->get('evercurrent_status_message') ?: t('No communication with server yet.');
  $severity = $state
    ->get('evercurrent_status');
  $severity = $severity || $severity === 0 ? $severity : RMH_STATUS_WARNING;
  $requirements['evercurrent_status'] = [
    'title' => t('Evercurrent: Runtime status'),
    'value' => $message,
    'severity' => $severity,
  ];
  return $requirements;
}