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.

Command icon Show commands

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

mably created an issue. See original summary.

mably’s picture

Issue summary: View changes
mably’s picture

Status: Active » Needs review

Converted 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 method DatetimeResetHooks::processElement(), registered via [self::class, 'processElement'] in elementInfoAlter(). Uses new TranslatableMarkup() instead of t() since it's a static method.

datetime_reset.services.yml — Explicit service registration with autowire: true for 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).

  • mably committed 66be63d2 on 1.0.x
    task: #3574775 Convert all hooks to OOP format.
    
    By: mably
    
mably’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.