You are here

function adsense_requirements in Google AdSense integration 8

Same name and namespace in other branches
  1. 5.3 adsense.module \adsense_requirements()
  2. 6 adsense.module \adsense_requirements()
  3. 7 adsense.install \adsense_requirements()

Implements hook_requirements().

File

./adsense.install, line 14
Install file of the adsense module.

Code

function adsense_requirements($phase) {
  $requirements = [];
  switch ($phase) {

    // At runtime, make sure that we have a publisher ID.
    case 'runtime':
      $basic_id = \Drupal::config('adsense.settings')
        ->get('adsense_basic_id');
      if (empty($basic_id)) {
        $url = Url::fromRoute('adsense.main_settings');
        $page = Link::fromTextAndUrl(t('AdSense settings page'), $url)
          ->toString();
        $requirements['adsense_basic_id'] = [
          'title' => t('AdSense'),
          'value' => t('Publisher ID is not set.'),
          'description' => t('Please configure it in the @page.', [
            '@page' => $page,
          ]),
          'severity' => REQUIREMENT_ERROR,
        ];
      }
      break;
  }
  return $requirements;
}