Issue #3640868: Fix security, coding standards and dependency injection issues

Summary

Resolves #3640868.

Fixes security, coding standards and dependency injection issues that block Drupal.org security advisory coverage (green shield) eligibility.

Problem

  • hook_help() concatenated raw HTML strings instead of returning plain text / render arrays.
  • Hooks accessed the service container directly (\Drupal::service(), \Drupal::config(), \Drupal::entityTypeManager()).
  • The node was rendered to a pre-rendered string and injected into the template, losing cache metadata.
  • Missing declare(strict_types=1) in several files; inconsistent with the hook class.
  • create() had a confusing union return type.
  • hook_help() and hook_theme_registry_alter() were implemented twice (once in the .module file via #[LegacyHook], once in the hook class).
  • No configure route, no default config, no published-check on the rendered node.

Root Cause

The module predates current Drupal coding standards and dependency injection best practices, leading to PHPCS/PHPStan violations and a maintenance page that renders a node outside proper render/cache semantics.

Solution

  • Return plain text from hook_help() (escaped via t() instead of HTML concatenation).
  • Move preprocess logic into MaintenancePageNodeHooks with constructor-injected ConfigFactoryInterface and EntityTypeManagerInterface.
  • Expose a render array (not a string) to maintenance_page_node_preprocess_maintenance_page, preserving the node's cache metadata.
  • Skip unpublished or missing nodes gracefully.
  • Add declare(strict_types=1) consistently.
  • Simplify create() to return static.
  • Remove duplicate hook implementations from the .module file.
  • Add configure route to .info.yml, add config/install/maintenance.node.yml, and document the schema with nullable: true.
  • Scope maintenance-page template markup with class names instead of broad intercepting IDs.

Validation Performed

  • Reviewed all changes against Drupal coding standards manually (no local PHP available in this environment).
  • Ran git diff --check — no whitespace errors.
  • Confirmed the module's only maintained branch is 1.x and targeted it.

Risks and Rollback

  • Risk: Low. Changes are internal implementation only; no user-facing behavior change, and rendering now honors node cache metadata.
  • Rollback: revert the commit on the issue branch.

Notes for Maintainers

  • Target branch: 1.x
  • Backport needed: No
  • Follow-up needed: None (could add automated tests for the preprocess/preview path in a follow-up)

Merge request reports

Loading
Loading