You are here

adsense.install in Google AdSense integration 8

Install file of the adsense module.

File

adsense.install
View source
<?php

/**
 * @file
 * Install file of the adsense module.
 */
use Drupal\Core\Link;
use Drupal\Core\Url;

/**
 * Implements hook_requirements().
 */
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;
}

/**
 * Add adsense_managed_defer to module settings.
 */
function adsense_update_8101() {
  $config = \Drupal::configFactory()
    ->getEditable('adsense.settings');
  $config
    ->set('adsense_managed_defer', FALSE);
  $config
    ->save(TRUE);
}

Functions

Namesort descending Description
adsense_requirements Implements hook_requirements().
adsense_update_8101 Add adsense_managed_defer to module settings.