Newer
Older

Lucas Hedding
committed
<?php
/**
* @file
* Contains automatic_updates.module..
*/
/**
* Implements hook_page_top().
*/
function automatic_updates_page_top(array &$page_top) {
/** @var \Drupal\Core\Routing\AdminContext $admin_context */
$admin_context = \Drupal::service('router.admin_context');
$route_match = \Drupal::routeMatch();
if ($admin_context->isAdminRoute($route_match->getRouteObject()) && \Drupal::currentUser()->hasPermission('administer site configuration')) {
$disabled_routes = [
'update.theme_update',
'system.theme_install',
'update.module_update',
'update.module_install',
'update.status',
'update.report_update',
'update.report_install',
'update.settings',
'system.status',
'update.confirmation_page',
];
// These routes don't need additional nagging.
if (in_array(\Drupal::routeMatch()->getRouteName(), $disabled_routes, TRUE)) {
return;

Lucas Hedding
committed
}
/** @var \Drupal\automatic_updates\Services\AutomaticUpdatesPsaInterface $psa */
$psa = \Drupal::service('automatic_updates.psa');
$messages = $psa->getPublicServiceMessages();
if ($messages) {
\Drupal::messenger()->addError(t('Drupal public service announcements:'));
foreach ($messages as $message) {
\Drupal::messenger()->addError($message);
}

Lucas Hedding
committed
}
}
}
/**
* Implements hook_theme().
*/
function automatic_updates_theme(array $existing, $type, $theme, $path) {
return [
'automatic_updates_psa_notify' => [
'variables' => [
'messages' => [],
],
],
];
}
/**
* Implements hook_cron().
*/
function automatic_updates_cron() {
/** @var \Drupal\automatic_updates\Services\NotifyInterface $notify */
$notify = \Drupal::service('automatic_updates.psa_notify');
$notify->send();
}
/**
* Implements hook_mail().
*/
function automatic_updates_mail($key, &$message, $params) {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$message['subject'] = $params['subject'];
$message['body'][] = $renderer->render($params['body']);
}