wallclock-1.0.x-dev/wallclock.module
wallclock.module
<?php
/**
* @file
* Hooks for Wallclock module.
*/
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function wallclock_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.wallclock':
$output = '<p>' . t('<strong>Wallclock</strong> provides a block containting an analog wallclock that shows default system time.') . '</p>';
$link = link::fromTextAndUrl(t('README'), Url::fromUri('internal:/help/ah/wallclock/README.md', ['attributes' => ['title' => t('Link to README.md.')]]));
$url = $link->toString();
if (\Drupal::moduleHandler()->moduleExists('advanced_help')) {
$output .= '<p>' . t("Additional help is available in the project's “@readme” file.", ['@readme' => $url]) . '</p>';
}
return $output;
default:
}
}
/**
* Implements wallclock_theme(). Adds theme to custom block.
*/
function wallclock_theme() {
/* Hardcode for now, should be configurable. */
$partsofday = [
5 => t('morning'),
10 => t('forenoon'),
12 => t('afternoon'),
17 => t('evening'),
21 => t('night'),
];
$hour = date('H');
if ($hour < 5) {
$pod = $partsofday[21];
}
elseif ($hour >= 21) {
$pod = $partsofday[21];
}
elseif ($hour >= 17) {
$pod = $partsofday[17];
}
elseif ($hour >= 12) {
$pod = $partsofday[12];
}
elseif ($hour >= 10) {
$pod = $partsofday[10];
}
elseif ($hour >= 5) {
$pod = $partsofday[5];
}
else {
$pod = t('unknow part of the day');
}
return [
'wallclock' => [
'variables' => [
'wallclock' => NULL,
'partofday' => $pod,
],
],
];
}
