Use attributes to define DataProducer plugins

Created on 20 March 2025, 6 months ago
Updated 7 August 2025, about 1 month ago

Problem/Motivation

Now that PHP 8 offers attributes, these are being adopted in Drupal core for plugin definitions, replacing the older annotation based plugins.

Let's adopt attribute based definitions for DataProducer plugins for the 5.x branch.

📌 Task
Status

Active

Version

5.0

Component

Code

Created by

🇧🇬Bulgaria pfrenssen Sofia

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

Merge Requests

Comments & Activities

  • Issue created by @pfrenssen
  • First commit to issue fork.
  • 🇦🇹Austria klausi 🇦🇹 Vienna

    Pull request ready.

    This was the final prompt for AI: "convert the doc block annotation to php attributes. use statement: "use Drupal\graphql\Attribute\DataProducer;". For ContextDefinition use Drupal\Core\Plugin\Context\ContextDefinition. keep the top doc comment sentence. use named parameters for all ContextDefinition constructors, the data type property is called "data_type". Use TranslatableMarkup for @Translation. make sure the use statements on top of the file are sorted alphabetically. for each property of ContextDefintion use a new line. If the data type of a context definition starts with "entity:" then use the class EntityContextDefinition with use statement Drupal\Core\Plugin\Context\EntityContextDefinition. If the data type of a context definition is exactly "entity" then use the class ContextDefinition with use statement Drupal\Core\Plugin\Context\ContextDefinition. Make sure that all multiline array elements have a comma at the end. Ensure that all context definitions in "consumes" are present in the attribute conversion and have the same name. the number of entries in "consumes" needs to be the same. If the class already has an attribute then skip the file."

    I took me 5 hours to create this pull request. Was I really faster with AI? Maybe a bit, but fiddling and reviewing changes also takes time. This might be a typical case where a developer thinks they are more productive with AI and suddenly 5 hours have passed.

    At least I enjoyed the refactoring more as I did not have to type out or copy/paste all the modifications. I would estimate that 95% of the changes the AI created correctly and the 5% rest I had to fix manually.

    I'm very thankful for the automated tests, which caught a lot of small mistakes that I then had to feed back into the prompt.

    I used Github copilot in agent mode with model Gemini 2.5 Pro.

  • 🇧🇬Bulgaria pfrenssen Sofia

    Thanks a lot for this and for sharing the process!

    • klausi committed 276a7162 on 5.x
      refactor(DataProducer): Convert doc annotations to attributes (#3514314)
      
  • 🇦🇹Austria klausi 🇦🇹 Vienna

    merged.

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

Production build 0.71.5 2024