Loading
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()andhook_theme_registry_alter()were implemented twice (once in the.modulefile via#[LegacyHook], once in the hook class).- No
configureroute, 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 viat()instead of HTML concatenation). - Move preprocess logic into
MaintenancePageNodeHookswith constructor-injectedConfigFactoryInterfaceandEntityTypeManagerInterface. - 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 returnstatic. - Remove duplicate hook implementations from the
.modulefile. - Add
configureroute to.info.yml, addconfig/install/maintenance.node.yml, and document the schema withnullable: 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.xand 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)