- Status changed to Active
about 1 year ago 8:29pm 23 October 2023 - π¨π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".
- π³π±Netherlands bbrala Netherlands
- Status changed to Fixed
10 months ago 7:27pm 9 March 2024 - π³π±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.