You are here

function new_relic_rpm_requirements in New Relic 8

Same name and namespace in other branches
  1. 7 new_relic_rpm.install \new_relic_rpm_requirements()
  2. 2.x new_relic_rpm.install \new_relic_rpm_requirements()
  3. 2.0.x new_relic_rpm.install \new_relic_rpm_requirements()

Implements hook_requirements().

File

./new_relic_rpm.install, line 13
Install and uninstall functions for the New Relic module.

Code

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

  // We do not verify the extension at install time, to allow for testing when
  // it is not present.
  if ($phase == 'runtime') {
    $new_relic_loaded = extension_loaded('newrelic');
    $requirements['newrelic'] = [
      'title' => t('New Relic PHP Library'),
      'value' => $new_relic_loaded ? t('Exists') : t('Not loaded'),
      'severity' => $new_relic_loaded ? REQUIREMENT_OK : REQUIREMENT_ERROR,
    ];
    $api_key = \Drupal::config('new_relic_rpm.settings')
      ->get('api_key');
    $settings_url = Url::fromRoute('new_relic_rpm.settings')
      ->toString();
    $requirements['newrelic_apikey'] = [
      'title' => t('New Relic API key'),
      'value' => $api_key == '' ? t('Not set (<a href=":configure">configure</a>)', [
        ':configure' => $settings_url,
      ]) : t('Available (<a href=":configure">configure</a>)', [
        ':configure' => $settings_url,
      ]),
      'severity' => $api_key == '' ? REQUIREMENT_INFO : REQUIREMENT_OK,
    ];
  }
  return $requirements;
}