diff --git a/scheduler.admin.inc b/scheduler.admin.inc index 6b9b780..e6eb4bc 100644 --- a/scheduler.admin.inc +++ b/scheduler.admin.inc @@ -7,8 +7,6 @@ use Drupal\Component\Utility\String; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Session\AccountInterface; -use Drupal\Core\Url; /** * Helper function for the real hook_form_node_type_form_alter(). @@ -233,60 +231,6 @@ function _scheduler_generate_key(array $form, FormStateInterface $form_state) { } /** - * Page callback: Generate the timecheck admin page. - */ -function _scheduler_timecheck() { - return theme('scheduler_timecheck', array('now' => REQUEST_TIME)); -} - -/** - * Returns HTML the timecheck administration page. - * - * @param array $variables - * An associative array containing: - * - 'now': A UNIX timestamp to format. - * - * @ingroup themeable - */ -function theme_scheduler_timecheck($variables) { - $account = \Drupal::currentUser(); - - $now = $variables['now']; - $date_default_timezone = variable_get('date_default_timezone', date_default_timezone_get()); - - $t_options = array( - // For @utc specify 'GMT' as the timezone (4th parameter) so that no - // timezone offset is returned. - '@utc' => format_date($now, 'custom', 'jS F Y, H:i:s P', 'GMT'), - // For @localtime do not specify any timezone parameter so that the user or - // site default setting is returned. - '@localtime' => format_date($now, 'custom', 'jS F Y, H:i:s P T e'), - '@daylight_saving' => format_date($now, 'custom', 'I') ? t('currently in daylight saving mode') : t('not in daylight saving mode'), - '@user_account' => Url::fromRoute('entity.user.edit_form', array('user' => $account->id())), - '@date_default_timezone' => String::checkPlain($date_default_timezone), - '@date_default_offset' => format_date($now, 'custom', 'P', $date_default_timezone), - '@date_default_code' => format_date($now, 'custom', 'T', $date_default_timezone), - '@admin_regional_settings' => Url::fromRoute('system.regional_settings'), - ); - - $output = '

' . t('Time check') . '

' - . '

' . t('Your server\'s time is @utc. In most cases this should match Greenwich Mean Time (GMT) / Coordinated Universal Time (UTC)', $t_options) . '

' - . '

' . t('The website default timezone is @date_default_timezone (@date_default_code) which is offset from GMT by @date_default_offset hours. This timezone can be changed by admin users with the appropriate access.', $t_options) . '

'; - - if (variable_get('configurable_timezones', 1)) { - $output .= '

' . t('Your local time is @localtime (@daylight_saving). You can change this via your user account.', $t_options) . '

'; - if (!$account->getTimezone()) { - $output .= '

' . t('Note: The user timezone has not been stored, so defaulting to the website timezone.') . '

'; - } - } - else { - $output .= '

' . t('Your local time is @localtime (@daylight_saving). This is not configurable by you.', $t_options) . '

'; - } - - return $output; -} - -/** * Page callback: Displays a list of nodes scheduled for (un)publication. * * This will appear as a tab on the content admin page ('admin/content'). It is diff --git a/scheduler.install b/scheduler.install index ec01632..25e9422 100644 --- a/scheduler.install +++ b/scheduler.install @@ -6,6 +6,65 @@ */ /** + * Implements hook_requirements(). + */ +function scheduler_requirements($phase) { + $requirements = array(); + + // Report server internal clock. + if ($phase === 'runtime') { + $user = \Drupal::currentUser(); + + $now = REQUEST_TIME; + $system_date = \Drupal::config('system.date'); + $date_default_timezone = $system_date->get('timezone.default') ?: date_default_timezone_get(); + $date_formatter = \Drupal::service('date.formatter'); + + $t_options = array( + // For %utc specify 'GMT' as the timezone (4th parameter) so that no + // timezone offset is returned. + '%utc' => $date_formatter->format($now, 'custom', 'jS F Y, H:i:s P', 'GMT'), + // For %localtime do not specify any timezone parameter so that the user or + // site default setting is returned. + '%localtime' => $date_formatter->format($now, 'custom', 'jS F Y, H:i:s P T e'), + '%daylight_saving' => $date_formatter->format($now, 'custom', 'I') ? t('currently in daylight saving mode') : t('not in daylight saving mode'), + '%date_default_timezone' => $date_default_timezone, + '%date_default_offset' => $date_formatter->format($now, 'custom', 'P', $date_default_timezone), + '%date_default_code' => $date_formatter->format($now, 'custom', 'T', $date_default_timezone), + '!account_edit' => \Drupal::url('entity.user.edit_form', ['user' => $user->id()]), + '!admin_regional_settings' => \Drupal::url('system.regional_settings'), + '!link_gmt' => 'https://www.google.com/search?q=Greenwich%20Mean%20Time', + ); + + $description = ''; + $description .= t('Your server\'s time is %utc. In most cases this should match Greenwich Mean Time (GMT) / Coordinated Universal Time (UTC)', $t_options); + $description .= '
' . t('The website default timezone is %date_default_timezone (%date_default_code) which is offset from GMT by %date_default_offset hours. This timezone can be changed by admin users with the appropriate access.', $t_options); + + if ($system_date->get('timezone.user.configurable')) { + $description .= '
' . t('Your local time is %localtime (%daylight_saving). You can change this via your user account.', $t_options); + if (!$user->getTimezone()) { + $description .= '
' . t('Note: The user timezone has not been stored, so defaulting to the website timezone.'); + } + } + else { + $description .= '
' . t('Your local time is %localtime (%daylight_saving). This is not configurable by you.', $t_options); + } + + $requirements['scheduler_timecheck'] = array( + 'title' => t('Time Check'), + 'value' => t('%utc', $t_options), + 'description' => array( + '#type' => 'inline_template', + '#template' => '{{ description|raw }}', + '#context' => array('description' => $description), + ), + ); + } + + return $requirements; +} + +/** * Implements hook_schema(). */ function scheduler_schema() { diff --git a/scheduler.module b/scheduler.module index dc4e966..b402158 100644 --- a/scheduler.module +++ b/scheduler.module @@ -65,15 +65,6 @@ function scheduler_menu() { 'weight' => 10, 'file' => 'scheduler.admin.inc', ); - $items['admin/config/content/scheduler/timecheck'] = array( - 'title' => 'Time Check', - 'description' => 'Allows site admin to check their servers internal clock', - 'page callback' => '_scheduler_timecheck', - 'access arguments' => array('administer scheduler'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 15, - 'file' => 'scheduler.admin.inc', - ); $items['admin/content/scheduler'] = array( 'title' => 'Scheduled', 'page callback' => 'scheduler_list', @@ -666,17 +657,6 @@ function _scheduler_scheduler_api(NodeInterface $node, $action) { } /** - * Implements hook_theme(). - */ -function scheduler_theme() { - return array( - 'scheduler_timecheck' => array( - 'arguments' => array('now' => NULL), - ), - ); -} - -/** * Implements hook_views_api(). */ function scheduler_views_api() {