You are here

function google_analytics_counter_requirements in Google Analytics Counter 8.3

Same name and namespace in other branches
  1. 7.3 google_analytics_counter.install \google_analytics_counter_requirements()
  2. 7.2 google_analytics_counter.install \google_analytics_counter_requirements()

Implements hook_requirements().

File

./google_analytics_counter.install, line 18
Update, and uninstall functions for the Google Analytics Counter module.

Code

function google_analytics_counter_requirements($phase) {

  // Only check requirements during the run-time (aka Status Report).
  if ($phase != 'runtime') {
    return [];
  }
  $requirements = [];

  // Verify that the user has authenticated with Google Analytics.
  // If not, display a warning on the status page.
  $t_args = [
    ':href' => Url::fromRoute('google_analytics_counter.admin_auth_form', [], [
      'absolute' => TRUE,
    ])
      ->toString(),
    '@href' => 'authentication form',
  ];

  /* @var \Drupal\google_analytics_counter\GoogleAnalyticsCounterAuthManagerInterface $auth_manager */
  $auth_manager = Drupal::service('google_analytics_counter.auth_manager');
  if ($auth_manager
    ->isAuthenticated() === TRUE) {
    $requirements['google_analytics_counter_authentication'] = [
      'title' => t('Google Analytics Counter'),
      'description' => t('You can revoke authentication on the <a href=:href>@href</a>.', $t_args),
      'severity' => REQUIREMENT_OK,
      'value' => t('Google Analytics have been authenticated.'),
    ];
  }
  else {
    $requirements['google_analytics_counter_authentication'] = [
      'title' => t('Google Analytics Counter'),
      'description' => t('Authenticate with Google on the <a href=:href>@href</a>.', $t_args),
      'severity' => REQUIREMENT_ERROR,
      'value' => t('Google Analytics have not been authenticated.'),
    ];
  }
  return $requirements;
}