Closed (fixed)
Project:
Publication Date
Version:
3.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
20 Feb 2026 at 14:15 UTC
Updated:
6 Mar 2026 at 16:40 UTC
Jump to comment: Most recent
Drupal 11 introduces a new attribute-based hook system (#[Hook()]) that replaces the traditional procedural .module hook implementations. While procedural hooks still work via #[LegacyHook], they are deprecated and will be removed in a future major version.
Converting our hooks to OOP format ensures forward compatibility, aligns with Drupal core's direction, and brings the benefits of class-based architecture: better testability, autoloading, and clearer code organization.
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
mably commentedConverted all procedural hooks in
publication_date.moduleto OOP format using#[Hook]attributes with#[LegacyHook]backward compatibility.New file
src/Hook/PublicationDateHooks.php — OOP hook class with
#[Hook]attributes for:hook_help()->help()hook_entity_base_field_info()->entityBaseFieldInfo()hook_form_node_form_alter()->formNodeFormAlter()hook_clone_node_alter()->cloneNodeAlter()hook_field_formatter_info_alter()->fieldFormatterInfoAlter()The
formNodeFormAlter()method injectsAccountProxyInterfacevia constructor instead of calling\Drupal::currentUser()directly.Updated files
publication_date.module — All procedural hooks now carry
#[LegacyHook]and delegate to\Drupal::service(PublicationDateHooks::class).publication_date.services.yml — Added the hooks class entry with
autowire: truefor theAccountProxyInterfacedependency.Not converted
publication_date.install(hook_installis in the OOP deny list) andpublication_date.post_update.php(post_update hooks are not convertible) were left as-is.Tests
All 13 existing tests pass (155 assertions).
Comment #5
mably commented