You are here

function timezone_detect_requirements in Timezone Detect 8

Same name and namespace in other branches
  1. 6 timezone_detect.install \timezone_detect_requirements()
  2. 7 timezone_detect.install \timezone_detect_requirements()

Implements hook_requirements().

File

./timezone_detect.install, line 16
(Un)installs the Timezone Detect module.

Code

function timezone_detect_requirements($phase) {
  $requirements = array();
  switch ($phase) {
    case 'runtime':
      $system_date_config = \Drupal::config('system.date');
      $timezone_detect_config = \Drupal::config('timezone_detect.settings');

      // Check that default user timezone is set to "empty timezone", or that
      // Timezone Detect is configured to update user timezone on every login
      // (otherwise automatic timezone detection will not work).
      $default_timezone_okay = FALSE;
      if ($timezone_detect_config
        ->get('mode') != TimezoneDetectInterface::MODE_DEFAULT || $system_date_config
        ->get('timezone.user.configurable') && $system_date_config
        ->get('timezone.user.default') == UserInterface::TIMEZONE_EMPTY) {
        $default_timezone_okay = TRUE;
      }
      if (!$default_timezone_okay) {
        $requirements['timezone_detect'] = array(
          'title' => t('Timezone detect'),
          'value' => t('Incompatible default user timezone'),
          'description' => t('For automatic timezone detection to work correctly, please change default user timezone to "empty timezone" on your site\'s <a href=":regional_settings_url">regional settings page</a>.', [
            ':regional_settings_url' => Url::fromRoute('timezone_detect.admin')
              ->toString(),
          ]),
          'severity' => REQUIREMENT_ERROR,
        );
      }
      break;
  }
  return $requirements;
}