Updated: Comment #1

Problem/Motivation

A while back, api.drupal.org was set up with an Annotations topic:
https://api.drupal.org/api/drupal/core!modules!system!system.api.php/gro...

Automatically, every Annotation class (identified with @Annotation in the doc block, excluding core/vendor) is shown there, and there's some documentation on the @defgroup annotation block that tells a bit about annotation.

So far, so good... But today I found out on #2107429-9: EntityType annotation doc blocks do not meet our standards from tim.plunkett that in contrast to when this was set up, we are no longer documenting the components of all annotations on the Annotation classes. Instead, some of them have been converted to Object-based instead of Array-based annotation, and they are being documented on other classes and/or interfaces with get/set methods. So for instance, the EntityType annotation class doesn't document anything that you'd actually need to put in your @EntityType annotation to define an entity type.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Annotation...

Proposed resolution

Add additional information to each of the object-based annotation classes linking to the interface/class that documents the get/set methods and annotation properties.

Remaining tasks

1. Propose wording about how to find docs for annotations for the @defgroup annotation block in core/modules/system/system.api.php, and make a patch. Don't want to do that now

2. [Done] Make a list of the existing Annotations classes on https://api.drupal.org/api/drupal/core!modules!system!system.api.php/gro... that need to be updated.

Annotation class Interface(s) with documentation
core/lib/Drupal/Core/Entity/Annotation/EntityType.php core/lib/Drupal/Core/Entity/EntityTypeInterface.php

note: It turns out that EntityType is the only object-based annotation at this time.

3. Make a patch that puts additional documentation on all the annotation classes listed in (2) to link to the appropriate classes and interface(s).

User interface changes

None.

API changes

None.

Comments

jhodgdon’s picture

Issue summary: View changes
Issue tags: +Novice

I am marking this as a Novice project, and I've updated the issue summary with several tasks that are certainly open to new or experienced contributors. Please help out!

richard.c.allen2386’s picture

Status: Active » Needs review
StatusFileSize
new506 bytes

I was looking at the original issue and started all the commotion about it being deprecated and moved around. I'm trying to figure out the documentation and how it works to start work on the issue but we're at a loss.

As far as I can tell their are multiple annotation types now in core https://drupal.org/node/2086397 and each base class should have a particular 'type' of plugin declaration (this may not be the correct terminology). I wrote up a little patch to get the issue started, is the the type of change we are talking about for the second and third part of the tasks? If so I can continue up the issue a bit and move it further along I'd just like to be sure I'm doing this correctly.

jhodgdon’s picture

Ummm... What I was trying to say in the issue summary is that on the Annotation class, to have an @see to the Interface class. Vice versa is probably good too, but the @see on the Annotation class will give people a link from the Annotations topic to documentation on how to annotate their plugin classes.

richard.c.allen2386’s picture

Sorry I'm still wrapping my head around this namespace/psr-0 stuff.

An annotation class would live at /core/lib/Drupal/Core/Field/Annotation/FieldBase.php in my example correct? I don't see this class on HEAD in 8.x so I'm a bit confused at how the @see you think we need fits in. Can you possible post a small patch pushing mine to the next step so I can see the example? I realize you gave the EntityType.php above but it's still not 100% clear to me after looking at the classes for a while.

Edit: I realize that you may mean there is a drupal core AnnotationBase.php or something similar, I'll look into it hopefully a bit tonight to see if I can figure that out.

jhodgdon’s picture

Let's see, I haven't looked at field annotation.

So here's my thought process. First I go to the Annotations topic at:
https://api.drupal.org/api/drupal/core!modules!system!system.api.php/gro...

I scroll down to FieldType, which links to:
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Field!Annotation!...
So that is the Annotation class for defining Field Types.

It looks like that Annotation class already has a bunch of documentation on it of the components you would need in order to define a field, so perhaps this class hasn't been updated like EntityType was? I really haven't been following this process (this whole thing was news to me yesterday), so I think we need to get someone who actually knows what is going on here to comment. I'll ask tim.plunkett, since he posted the original comment that sparked this issue.

jhodgdon’s picture

Title: All annotation classes need @see links to interfaces » Object-based Annotation classes need links to interfaces
Issue summary: View changes

Dang. I am really sorry.

So, I just had a conversation with tim.plunkett in IRC and it turns out that EntityType is the only annotation class for which there is a problem, because it has been changed from being a simple array-type plugin annotation/discovery, to an object-type plugin annotation/discovery. All of the other annotation types are array-type and they are properly documented in the annotation classes.

So what we need is just for the EntityType annotation class (in core/lib/Drupal/Core/Entity/Annotation/EntityType.php) to have some information added to it, a paragraph saying something like this:

Entity type plugins use an object-based annotation method, rather than an array-type annotation method. The annotation properties of entity types are found on \Drupal\Core\Entity\EntityType, and are accessed using the get/set methods defined in \Drupal\Core\entity\EntityTypeInterface.

(thanks to Tim for clearing this up for me).

I'll update the issue summary and title.

jhodgdon’s picture

Status: Needs review » Needs work
paulh’s picture

Assigned: Unassigned » paulh
paulh’s picture

@jhodgdon is this what you meant? Just cleaned up the advised text a bit and added a @see to the doco.

paulh’s picture

Status: Needs work » Needs review
jhodgdon’s picture

Status: Needs review » Needs work

Looks good! The only thing is that instead of putting in the HTTP link to a specific api.drupal.org page in

+ * @see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21Annotation%21EntityType.php/class/EntityType/8

you should instead do @see \Fully\Namespaced\Name\Of\Class

The reason is that this documentation block may have a very long life (Drupal 8, Drupal 9, Drupal 10, ... plus we may have 8.0.1 etc. so the URLs could change), and also there are other sites like api.drupal.org that would want the links to stay internal to their site.

Thanks!

paulh’s picture

Status: Needs work » Needs review
StatusFileSize
new808 bytes

Updated as per suggestion to reference the fully namespaced class and re-rolled the patch.

@jhodgdon: thankyou for your patient guidance. I really appreciate it.

Status: Needs review » Needs work

The last submitted patch, 12: object-based-annotation-classes-doco-2189497-12.patch, failed testing.

paulh’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 12: object-based-annotation-classes-doco-2189497-12.patch, failed testing.

paulh’s picture

Status: Needs work » Needs review
StatusFileSize
new808 bytes

Try again.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! That looks good. The previous patch ran into both of the random test failures that is being tracked down today and yesterday -- so it wasn't your patch that was the problem.

paulh’s picture

Thanks for the feedback - the test failures did have me scratching my head for a bit. Cheers.

jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

Thanks again! Committed to 8.x.

Status: Fixed » Needs work

The last submitted patch, 16: object-based-annotation-classes-doco-2189497-16.patch, failed testing.

jhodgdon’s picture

Status: Needs work » Fixed

Test bot is too fast. Queued patch above for retest just before I committed it.

Status: Fixed » Closed (fixed)

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