Closed (fixed)
Project:
DateTime Reset
Version:
1.0.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
20 Feb 2026 at 11:22 UTC
Updated:
6 Mar 2026 at 13:10 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 #2
mably commentedComment #3
mably commentedConverted all procedural hooks to OOP format using
#[Hook]attributes with#[LegacyHook]backward compatibility.New files
src/Hook/DatetimeResetHooks.php — OOP hook class with
#[Hook]attributes for:hook_element_info_alter()->elementInfoAlter()hook_field_widget_single_element_form_alter()->fieldWidgetSingleElementFormAlter()hook_field_widget_third_party_settings_form()->fieldWidgetThirdPartySettingsForm()hook_field_widget_settings_summary_alter()->fieldWidgetSettingsSummaryAlter()The private
_datetime_reset_process_element()helper was moved to a public static methodDatetimeResetHooks::processElement(), registered via[self::class, 'processElement']inelementInfoAlter(). Usesnew TranslatableMarkup()instead oft()since it's a static method.datetime_reset.services.yml — Explicit service registration with
autowire: truefor Drupal 10.x backward compatibility (where#[Hook]auto-discovery is not available).Updated files
datetime_reset.module — All procedural hooks now carry
#[LegacyHook]and delegate to\Drupal::service(DatetimeResetHooks::class). The_datetime_reset_process_element()function was removed.Tests
Both existing tests pass (AdminPageTest + DateTimeResetTest).
Comment #6
mably commented