Problem/Motivation

Follow-up from #3252386: Use PHP attributes instead of doctrine annotations and pointed out by @xjm. We should document attribute discovery in the handbook.

https://www.drupal.org/docs/drupal-apis/plugin-api has a section on annotations, could add a parallel one, and add note in the annotations page pointing to it.

There'll also be lots of individual examples of plugins using annotations that need updating over time to use attributes instead, but these will need to wait for individual subsystems to support attributes.

Steps to reproduce

Proposed resolution

Added Attribute-based plugins to the Plugin API docs.
Added attribute discover to Drupal Plugin discovery

Remaining tasks

What else?

User interface changes

API changes

Data model changes

Release notes snippet

Comments

catch created an issue. See original summary.

xjm’s picture

berdir’s picture

Adding this to the meta issue about the conversion (which I think would be a better parent for this, but don't want to just change that).

longwave’s picture

We need to ensure we document the outcome of #3400458: AttributeClassDiscovery fails while trying to include non valid plugin class, as there are stricter rules for what can exist in the namespace for pure attribute discovery compared to annotations.

xjm’s picture

Title: Document attribute based discovery in the handbook » Document attribute-based discovery in the handbook
quietone’s picture

There is an existing page for 'Drupal Plugin Discovery' which lists four methods, StaticDiscovery, HookDiscovery, AnnotatedClassDiscovery and YamlDiscovery. That seems like a suitable place to add 'Attribute discovery'. Would that work?

quietone’s picture

Added a page for attribute plugins, which is basic and needs work, https://www.drupal.org/docs/drupal-apis/plugin-api/attribute-based-plugins

quietone’s picture

Issue summary: View changes
Status: Active » Needs review

What more needs to be done here?

smustgrave’s picture

Status: Needs review » Postponed (maintainer needs more info)

Can this be closed per #6?

longwave’s picture

Status: Postponed (maintainer needs more info) » Needs work

I think we should extend the page to include "Using attributes in your own plugin type" similar to the annotations example at https://www.drupal.org/docs/drupal-apis/plugin-api/annotations-based-plu...

quietone’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Reviewing just the section mentioned in #11 change makes sense based on reviews of the attribute tickets.

But question on "Defining a plugin" section.

a key for an optional deriver class

we've been requiring that for attributes so should optional be removed. Either way seemed out of scope for this ticket so maybe a follow up.

catch’s picture

The deriver class is optional, the key is not.

quietone’s picture

I added another page, Create a custom attribute class. And that states that the deriver key is required in the Attribute class.

catch’s picture

Status: Reviewed & tested by the community » Fixed

I think this is good progress, and we can refine it as time goes on. Eventually we'll need to deprecate and retire the annotations documentation but need to deprecate annotations first and that's still quite far off.

Status: Fixed » Closed (fixed)

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