Provide automatic conversion from annotations to native attributes

Created on 22 February 2022, over 2 years ago
Updated 23 March 2024, 3 months ago

Drupal version

10.0.x

Drupal Rector version

TBD

Problem / Motivation

Part of πŸ“Œ Use PHP attributes instead of doctrine annotations Fixed

While there's MVP patch to replace annotations with attributes as Drupal 10.0 require PHP 8.1

ATM parent issue work is about to define replacements to doctrine annotation which gonna be deprecated

πŸ“Œ Task
Status

Fixed

Component

Code

Created by

πŸ‡«πŸ‡·France andypost

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • Status changed to Active 8 months ago
  • πŸ‡¨πŸ‡­Switzerland Berdir Switzerland

    Drupal uses different classes for Annotation and Attribute discovery, so it will require a mapping/logic to derive the Attribute class from the Annotation. We also don't use namespaces in Annotations, so that's an extra hurdle for rector to understand.

    The core issue is getting close and having this could be extremely beneficial in getting all the remaining core plugin types converted, doing that by hand especially for big ones like entity types is *painful*. So setting this to active in the hope that someone who knows rector gives this a try :)

  • πŸ‡«πŸ‡·France andypost

    https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview...

    there's existing rector which just needs configuration

  • πŸ‡¨πŸ‡­Switzerland Berdir Switzerland

    Early findings:

    https://getrector.com/blog/how-to-upgrade-annotations-to-attributes mentions DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES, that is vendor/rector/rector-doctrine/config/sets/doctrine-annotations-to-attributes.php, which is a hardcoded list of annotation => attribute classes.

    That seems like a good start to work on core plugin types, but any contrib and plugin type annotation discovery will need to be converted as well. The optimal case would be that we somehow find those dynamically, with a few patterns for nested stuff like the translation. No idea if that's possible, as that would imply dynamic configuration OR complex, dynamic conversions with state?

    Generic rule to find the Attribute class from the Annotation class would be something like: Drupal\foo\Annotation\Bar => Drupal\foo\Attribute\Bar. See https://www.drupal.org/node/3395575 β†’ . Action is a special early case that was in a different namespace, those should be limited and specific to Drupal\Core annotations.

    Another aspect is to convert plugin types, while less common, they are still very common. http://grep.xnddx.ru/search?text=extends%20DefaultPluginManager finds 67 pages of DefaultPluginManager subclasses. Not all of them use annotation discovery, but many do. That will involve creating entire new attribute classes, I've now idea how feasible that is.

    @mglaman had this to say on this whole topic:
    > Lol this looks like a nightmare waiting to happen

  • πŸ‡«πŸ‡·France andypost

    WIP PR https://github.com/palantirnet/drupal-rector/pull/257

    Looks like it will need specific parser per annotation with mapping of each key, also will need some formatting to split one argument per line

  • πŸ‡ΊπŸ‡ΈUnited States Amber Himes Matz Portland, OR USA

    Updated title to fix typo in "annotations" to ensure issue is discoverable in searches for "annotations".

  • Status changed to Fixed 4 months ago
  • πŸ‡³πŸ‡±Netherlands bbrala Netherlands

    The rector is available now, with some docs, it wont cover everything, but it seems to function quite well with out structure. Now we just need to see how many edge cases we run into.

    Guess we should create new issues when they arrive.

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

Production build 0.69.0 2024