Skip to content
Snippets Groups Projects
google_analytics.install 1.61 KiB
Newer Older
bcweaver's avatar
bcweaver committed
<?php

/**
 * @file
 * Installation file for Google Analytics module.
 */

use Drupal\Core\Url;

/**
 * Implements hook_uninstall().
 *
 * Remove cache directory if module is uninstalled.
 */
function google_analytics_uninstall() {
  google_analytics_clear_js_cache();
}

/**
 * Implements hook_requirements().
 */
function google_analytics_requirements($phase) {
  $requirements = [];

  if ($phase == 'runtime') {
    $config = \Drupal::config('google_analytics.settings');

    // Raise warning if Google user account has not been set yet.
    if (!preg_match('/^UA-\d+-\d+$/', $config->get('account'))) {
      $requirements['google_analytics_account'] = [
        'title' => t('Google Analytics module'),
        'description' => t('Google Analytics module has not been configured yet. Please configure its settings from the <a href=":url">Google Analytics settings page</a>.', [':url' => Url::fromRoute('google_analytics.admin_settings_form')->toString()]),
        'severity' => REQUIREMENT_WARNING,
        'value' => t('Not configured'),
      ];
    }
    // Raise warning if debugging is enabled.
    if ($config->get('debug')) {
      $requirements['google_analytics_debugging'] = [
        'title' => t('Google Analytics module'),
        'description' => t('Google Analytics module has debugging enabled. Please disable debugging setting in production sites from the <a href=":url">Google Analytics settings page</a>.', [':url' => Url::fromRoute('google_analytics.admin_settings_form')->toString()]),
        'severity' => REQUIREMENT_WARNING,
        'value' => t('Debugging enabled'),
      ];
    }
  }

  return $requirements;
}