Backport Hook and LegacyHook Attribute

Created on 22 October 2024, 2 months ago

Problem/Motivation

In order to use the BC layer and not have phpstan complain the hooks need to at least exist.

11.x is intentional I will also create a 10.4, and hopefully we can get 10.3 as well.

Steps to reproduce

Use legacyHook attribute, phpstan will complain.

Proposed resolution

Add Hook and LegacyHook attribute to 11.0, 10.4 and 10.3.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

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

    nicxvan β†’ changed the visibility of the branch 3482464-backport-hook-and to hidden.

  • πŸ‡¬πŸ‡§United Kingdom catch

    This is 100% eligible for 10.4.

    Need to get a second/third opinion from other committers about 11.0 and 10.3 - to me it makes sense because these classes will do literally nothing, they can even be empty (not that we should necessarily make them empty because that could be more confusing for people than having them the same as the 11.x versions).

  • Merge request !9906Backport Hook attributes β†’ (Open) created by nicxvan
  • Merge request !9907Backport Hook attributes β†’ (Open) created by nicxvan
  • Merge request !9908Backport Hook attributes β†’ (Closed) created by nicxvan
  • Pipeline finished with Success
    2 months ago
    Total: 1257s
    #317138
  • Pipeline finished with Success
    2 months ago
    Total: 1252s
    #317139
  • Pipeline finished with Success
    2 months ago
    Total: 1283s
    #317137
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • πŸ‡¨πŸ‡¦Canada Charlie ChX Negyesi 🍁Canada
  • 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
  • πŸ‡¦πŸ‡ΊAustralia elc

    Adding it to 10.3 and 11.0 would allow the work on converting contrib modules to get underway using BC method - this is going to be quite the code churn leading up to Drupal 12.

    Adding it to 11.0 is a no brainer - if it's added to 10.4, then it has to also exist in 11.0. Even if sites are expected to upgrade from 10.4 to 11.1, it's a real disconnect for a class not to appear in an intermediate version. It's harmless to add the classes. Any contrib module would need an exception to say "works with 10.4 through 11.1, but don't try it with 11.0 or it will WSOD your site". There will be D11.0 sites trying to use that code.

    It would be nice to add it to 10.3 (so I can start coding BC OO hooks) but there's no compelling reason it needs to be added. No contrib marked <=10.3 is going to have any of these BC OO hook wraps that it needs the classes to exist. Any contrib release that adds them would already need to state ^10.4.

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

    I hope it gets in all three versions too.

    works with 10.4 through 11.1, but don't try it with 11.0 or it will WSOD your site

    Just a note the worst that should happen is phpstan complaining the attributes are not used until 11.1

  • πŸ‡¦πŸ‡ΊAustralia elc

    PHP always surprises me; it really does just ignore an Attribute class not existing. I guess that's why the syntax is #[Blah] so that older versions ignore it as a comment.

  • πŸ‡¨πŸ‡¦Canada Charlie ChX Negyesi 🍁Canada

    The syntax to ignore is for older PHP versions indeed.

    But nonexisting attribute classes are ignored because PHP itself doesn't use attributes. Indeed, you can even run reflection against a function marked with LegacyHook in the absence of LegacyHook class, you can even retrieve the name of the attribute and it won't blow up until you try to instantiate it. There's no reason to run a class_exists against attributes. Much the same with use. It's just a string up to the point when you try to use it as an actual classname to instantiate. https://3v4l.org/sK4If As visible from this if we wanted to make a mess we didn't need to create the LegacyHook class at all, you can just check for the hook name whether it exists or not.

    This is why I said people stuck on 10.1 or something already are fine to use it or to use contrib using this attribute -- it just doesn't matter.

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    Would be helpful to get this in, I understand that it's not strictly required, but phpstan complains and that will confuse a lot of people.

    That said, I would recommend we do not just copy paste the documentation from 11.1, that is IMHO very confusing, but I'd epect that it would actually do something then on 10.x/11.0

    I would clearly state that the two attribute classes only exist in those core versions that people are looking at to satisfy phpstan and as a place to document that it doesn't actually do anything beside that before 11.1.

  • πŸ‡¬πŸ‡§United Kingdom catch

    Yep agreed with #16.

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

    Do you just want the class comments updated?

    How about something like:

    This class will not have an effect until Drupal 11.1.0.

    This class is to prevent phpstan errors for modules that support procedural and #Hook implementations.

  • πŸ‡¬πŸ‡§United Kingdom catch

    That looks good - maybe the below is a bit more explicit?

    This class is included in earlier Drupal versions to prevent phpstan errors for modules implementing object oriented hooks using the #Hook and #LegacyHook attributes.

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

    Ok let me update those.

  • Pipeline finished with Canceled
    about 1 month ago
    Total: 102s
    #342379
  • Pipeline finished with Canceled
    about 1 month ago
    Total: 189s
    #342378
  • Pipeline finished with Success
    about 1 month ago
    Total: 547s
    #342391
  • Pipeline finished with Success
    about 1 month ago
    Total: 3679s
    #342385
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • Pipeline finished with Success
    about 1 month ago
    Total: 9346s
    #342388
  • πŸ‡¬πŸ‡§United Kingdom catch

    RTBC for me. I wondered about removing the rest of the phpdoc (and maybe even the constructor itself) too but not sure there's much benefit to that, you either stop at the class summary or you don't.

    • catch β†’ committed 568ce2c6 on 10.4.x
      Issue #3482464 by nicxvan, berdir: Backport Hook and LegacyHook...
    • catch β†’ committed cfecbe36 on 10.5.x
      Issue #3482464 by nicxvan, berdir: Backport Hook and LegacyHook...
    • catch β†’ committed 5712beef on 11.0.x
      Issue #3482464 by nicxvan, berdir: Backport Hook and LegacyHook...
    • catch β†’ committed 2427e811 on 10.3.x
      Issue #3482464 by nicxvan, berdir: Backport Hook and LegacyHook...
  • πŸ‡¬πŸ‡§United Kingdom catch

    I RTBCd this but it was two weeks ago and there's been no further feedback. We need this in the 10.4.0 release and the next 11.0 patch release.

    Committed/pushed to 11.0.x/10.5.x/10.4.x/10.3.x - 10.2.x is about to go out of support and won't get any more patch releases.

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

Production build 0.71.5 2024