Bulk convert the remaining hooks to OOP

Created on 29 June 2025, 7 days ago

Problem/Motivation

In πŸ“Œ [ignore] Convert everything everywhere all at once Active we converted all procedural hooks we could at the time, but some were missed (mostly hook_theme_suggestions)

We should bulk convert the remaining hooks.

In slack @catch said we could do this shortly after 11.2 dropped.

I will convert all remaining hooks using rector (except node since there is a separate issue for that)

Steps to reproduce

N/A

Proposed resolution

Use rector

Remaining tasks

User interface changes

N/A

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component

base system

Created by

πŸ‡ΊπŸ‡ΈUnited States nicxvan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @nicxvan
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • Merge request !12541Resolve #3533049 "Bulk convert the" β†’ (Open) created by nicxvan
  • Pipeline finished with Failed
    7 days ago
    Total: 193s
    #534577
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • Pipeline finished with Failed
    7 days ago
    Total: 841s
    #534580
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • Pipeline finished with Success
    7 days ago
    Total: 664s
    #534702
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    Thought I had already set needs review.

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    nicxvan β†’ changed the visibility of the branch 11.x to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    I've updated the script and I'm running the conversion now.

  • Merge request !12626Resolve #3533049 "Convert remaining v2" β†’ (Open) created by nicxvan
  • Pipeline finished with Success
    2 days ago
    Total: 2242s
    #539343
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    nicxvan β†’ changed the visibility of the branch 3533049-bulk-convert-the to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    Others might disagree but my honest opinion after scanning through a part of this is that this is IMHO not really worth doing like this in this form.

    In many cases, this essentially creates unfinished conversions and therefore technical dept that we have to touch again anyway. I'm not clear what should be done in this issue and what not:

    * No DI
    * One reason block_themes_installed() should be next to block_modules_installed() (beside logical grouping) is that both call block_theme_initialize(), I would approach this as a dedicated issue and also convert that function to a protected method on the same Hook class. I think there's no value in providing this as an API. Then we're done with block.module except deprecated BC layers.
    * ContentModerationThemeHooks is a one-line wrapper calling the already oop-ified actual code. Lets' not move that but convert the actual implementation to a hook class.
    * file_deprecated_test_file_mimetype_mapping_alter() is already deprecated and just a test of the BC layer, per updated assertion messaage. converting this into OOP feels like unnecessary busywork?

    Maybe we reduce this to just the trivial bits, which is maybe 50% of the changes here?

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    I disagree which is not surprising, but I'll add the benefits that I see.

    1 this is automated, that means it is repeatable and id a few are correct they all are.

    One of the hardest parts of manual conversion is making sure things align properly. We have made that mistake before.

    2. It makes the diff to add DI fat smaller and easier to review.

    3. This removes 2 inc and 17 module files. Code that no longer has to load

    4 it is one disruption rather than many.

    5. Less likely to missed things because it is automated.

    In reference to your specific objections.

    It is more work and riskier to skip and add exceptions to the automated rector rule than just convert the wrapper and the deprecations.

  • πŸ‡ΊπŸ‡ΈUnited States fathershawn New York

    Steps to review

    Copied from a Slack thread

    1. Check the post applied patches
    2. Review or run the command to confirm the process
    3. Spot check a few different ones to confirm the location and copy is correct

    Checked the patches. All are cleanly applied unless noted.
    ✓ 0001-codesniff.patch
    ✓ 0002-manual-conversion.patch differs only in that visibility is added and a comment is edited in \Drupal\block\Hook\BlockHooks::themesInstalled
    ✓ 0003-testfix.patch
    ✓ 0004-deprecationfix.patch

    I have my core dev setup running under DDEV so I copied in your command from the snippets page, created a new branch off 11.x and ran your command, responding Y to all options. The result differed only slightly from the MR branch in some comment formatting and the replacement of some procedural calls to t() with the \Drupal\Core\StringTranslation\StringTranslationTrait::t method.

    Spot checked contents and attribute value of several hooks

Production build 0.71.5 2024