Problem/Motivation

The Vartheme BS5 theme implements its hooks as procedural functions in vartheme_bs5.theme. Drupal 11 provides object-oriented hooks via the #[Hook] attribute (change record), which are autoloaded and support dependency injection. Themes support OOP hook classes as of Drupal 11.2.

Steps to reproduce

Review vartheme_bs5.theme: the alter/registration hooks are procedural functions.

Proposed resolution

Move the convertible procedural hook implementations (hook_theme, hook_library_info_alter, hook_form_alter) into an object-oriented hook class Drupal\vartheme_bs5\Hook\VarthemeBs5Hooks using the #[Hook] attribute, with the theme extension list injected via the constructor. The many preprocess hooks and the vartheme_bs5_process_menu_level() helper are kept procedural in the .theme file.

Remaining tasks

  • ✅ Add src/Hook/VarthemeBs5Hooks.php
  • ✅ Clean vartheme_bs5.theme (keep preprocess + helper)
  • ➖ Keep preprocess hooks procedural
  • ❌ Reviewed by a human

User interface changes

None.

API changes

None. These are standard theme hooks invoked by core only; see the OOP hooks change record.

Data model changes

None.

Release notes snippet

Converted the Vartheme BS5 procedural hook_theme, hook_library_info_alter and hook_form_alter implementations to a Drupal 11 object-oriented hook class.

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

rajab natshah created an issue. See original summary.

  • rajab natshah committed c56658ba on 4.0.x
    task: #3608328 Convert the procedural hooks to OOP hook classes in the...
rajab natshah’s picture

Assigned: Unassigned » josebc
Status: Active » Needs review
Issue tags: +varbase-10.1.1, +vartheme_bs5-4.1.0
rajab natshah’s picture

Assigned: josebc » mohammed j. razem
rajab natshah’s picture

Assigned: mohammed j. razem » Unassigned
Status: Needs review » Fixed

✅ Released vartheme_bs5-4.1.0

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.