maintenance_page_node-1.0.0-beta2/maintenance_page_node.module
maintenance_page_node.module
<?php
/**
* @file
* Primary module hooks for Maintenance Node module.
*/
use Drupal\node\Entity\Node;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function maintenance_page_node_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the maintenance_page_node module.
case 'help.page.maintenance_page_node':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('This module allows you to choose a node to show when maintenance mode is on.
When the module is installed, navigate to maintenance mode form (admin/config/development/maintenance)
and an autocomplete node field is added. When this field is empty, the default message will be shown.') . '</p>';
return $output;
}
}
/**
* Implements hook_preprocess_template() for maintenance_page.
*
* Load node from config to show in maintenance mode.
*/
function maintenance_page_node_preprocess_maintenance_page(&$variables): void {
$maintenance_node_id = \Drupal::config('maintenance.node')->get('maintenance_node');
if (!$maintenance_node_id) {
return;
}
$node = \Drupal::service('entity_type.manager')->getStorage('node')->load($maintenance_node_id);
if (!($node instanceof Node)) {
return;
}
$builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$build = $builder->view($node, 'master');
$variables['maintenance_node'] = \Drupal::service('renderer')->render($build);
}
/**
* Implements hook_theme_registry_alter().
*/
function maintenance_page_node_theme_registry_alter(&$theme_registry): void {
$theme_registry['maintenance_page']['path'] = \Drupal::service('extension.list.module')->getPath('maintenance_page_node') . '/templates';
}
