Deprecate ModuleHandlerInterface::*Deprecated() in favor of hook metadata

Created on 20 September 2018, about 7 years ago
Updated 5 May 2025, 5 months ago

Problem/Motivation

#2866779: Add a way to trigger_error() for deprecated hooks β†’ added ways to mark hooks deprecated by introducing new API methods. This means we needed one new API method for every method hooks can be invoked, adding three new methods for one small purpose, as well as putting the deprecation burden not on the hook owner, but the owner of every single invocation of deprecated hooks, and while we tend to wrap hook invocations in their own API methods, invoking hooks without API wrappers used to be common practice for a long time.

Proposed resolution

We can deprecate these three ::*Deprecated() methods and put the burden of deprecation solely with hook owners by marking hooks deprecated in hook_hook_info() implementations:
Before Drupal 8.7:

\Drupal::moduleHandler()->invokeDeprecated('foo_bar');

Drupal 8.7:

function foo_hook_info() {
return [
  'foo_bar' => [
    'deprecated' => 'hook_foobar() has been deprecated since Drupal 8.7. Use hook_foo_baz() instead. See https://drupal.org/node/foo_bar',
  ],
]
}

ModuleHandler::getImplementations() will trigger errors for any implementations of deprecated hooks.

Remaining tasks

  • Deprecate the change record β†’ for the original change and document this new deprecation flag.
  • Convert all usages of the three deprecated methods in Drupal core.

User interface changes

None.

API changes

ModuleHandlerInterface::*Deprecated() will become deprecated.

Data model changes

One optional addition to hook_hook_info()'s return value.

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component

extension system

Created by

πŸ‡¬πŸ‡§United Kingdom xano Southampton

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

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

    Well, hook_hook_info is now deprecated is there another way to do this?

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

    I don't see anyway to do this now that we don't have hook hook info.

    I think invocation time is the way to do it anyway.

  • Status changed to Active about 1 month ago
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • Pipeline finished with Failed
    about 1 month ago
    #586254
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • Pipeline finished with Failed
    about 1 month ago
    Total: 666s
    #586271
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    I understand the idea and generally it makes sense, but at a glance, a few things jump out to me as awkward:

    a) the location of the attribute. Putting them on a hooks class seems weird. What if your module doesn't implement any hooks? This would be different if we'd have explicit Hook attribute classes, then we could deprecate those, which would also directly expose that information to anyone using those hooks (assuming that IDE's have a concept of deprecated attributes). Attributes are great because it allows you to add metadata next to the actual thing, but there is no thing here. Maybe this could use a yaml file, but that brings me to the second point.

    b) Dynamic hooks. What if we deprecate hook_form_FORM_ID_alter(), or hook_ENTITY_TYPE_load()? What if only _some_ of those are deprecated? Lets say we deprecate hook_form_BASE_FORM_ID_alter() but not hook_form_FORM_ID_alter()? Even if we'd support regex or wildcard, this will be imperfect and will possibly flag certain hooks incorrectly as deprecated that aren't.

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

    Thank you for taking a look.

    I had considered this.

    a) yes I understand, but those issues exist with the current method as well with two added problems that this solves.
    1 you can deprecate without using module handler.
    2 It keeps the hook metadata in attributes extending a pattern that will get more familiar. Creating an empty class isn't a huge burden, I did that for the core hook deprecations.

    I also think this is much nicer than yaml, you get hints when adding the attribute and you don't have to worry about indentation.

    b) While this may be valid, it is an issue with the current process too, you could not independently deprecate the dynamic stacked form alters. We could likely create a custom dynamic deprecation.

    In the end this cleans up an already overloaded service and gives us a cleaner way to do a rarely dive task.

    One thing we might want to do is add another parameter for dynamic hooks with a pattern.

  • Pipeline finished with Failed
    about 1 month ago
    Total: 657s
    #586811
  • Pipeline finished with Failed
    about 1 month ago
    Total: 584s
    #586835
  • Pipeline finished with Failed
    about 1 month ago
    Total: 219s
    #586849
  • Pipeline finished with Failed
    about 1 month ago
    Total: 645s
    #586883
  • Pipeline finished with Failed
    28 days ago
    Total: 1003s
    #588559
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    @dww on slack said we could delete the hook implementations.

    I am going to delete the three implementations instead of updating the deprecation skip.

  • Pipeline finished with Failed
    27 days ago
    Total: 508s
    #589565
  • Pipeline finished with Failed
    27 days ago
    Total: 694s
    #589586
  • Pipeline finished with Canceled
    26 days ago
    Total: 93s
    #590403
  • Pipeline finished with Success
    26 days ago
    Total: 913s
    #590404
  • Merge request !13160Resolve #3001190 "Test cs" β†’ (Open) created by nicxvan
  • Pipeline finished with Canceled
    26 days ago
    #590444
  • Pipeline finished with Canceled
    26 days ago
    Total: 204s
    #590445
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    nicxvan β†’ changed the visibility of the branch 3001190-test-cs to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • πŸ‡ΊπŸ‡Έ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.

  • Pipeline finished with Success
    13 days ago
    #602309
  • Pipeline finished with Canceled
    11 days ago
    Total: 315s
    #603751
  • Pipeline finished with Failed
    11 days ago
    Total: 367s
    #603760
Production build 0.71.5 2024