On #2148255: [meta] Make better D8 api.d.o landing page, linked to high-level overview topics, and put it in Core api.php files, we made a patch that included a stub Topic page for api.drupal.org (i.e., a @defgroup) titled:

Object-oriented programming conventions

This can be found in file core/modules/system/core.api.php where it says

@defgroup oo_conventions

The documentation to go on this page needs to be written. The idea is:

a) Write a few paragraphs about the topic.

b) Link to more detailed documentation on
https://drupal.org/developing/api/8

c) If the more detailed documentation does not yet exist, create stub page(s), link to the stub pages, and add a note to this issue stating that the stub pages need to be filled out.

d) If the topic has related classes, interfaces, and functions -- appropriate for an overview -- add

@ingroup oo_conventions

to their documentation headers. That will make these classes etc. show up on the Topic page on api.drupal.org. Only include classes/functions that are appropriate for an overview page please!

For more info -- documentation standards for @defgroup/@ingroup:
https://drupal.org/coding-standards/docs#defgroup

Comments

jhodgdon’s picture

Assigned: Unassigned » jhodgdon

Taking this on...

jhodgdon’s picture

Status: Active » Needs review
StatusFileSize
new2.48 KB

I think this, for a change relatively short, patch is probably enough for this topic. Thoughts?

webchick’s picture

Status: Needs review » Needs work

So my one beef with this is it puts the most critical information (you need to put your classes just so or nothing happens) at the end, and emphasizes the least critical (FYI, we have coding standards for this) at the top. Personally, I would more or less invert the list:

+ * - Each class must be in its own file.
+ * - In order for the PSR-4-based class auto-loader to find the class, it must
+ *   be located in a directory corresponding to the namespace. For
+ *   module-defined classes, if the namespace is \Drupal\module_name\foo\bar,
+ *   then the class goes under the main module directory in directory
+ *   src/foo/bar. For Drupal-wide classes, if the namespace is
+ *   \Drupal\Core\foo\bar, then it goes in directory
+ *   core/lib/Drupal/Core/foo/bar. See https://www.drupal.org/node/2156625 for
+ *   more information about PSR-4.
+ * - Classes must be namespaced. If a module defines a class, the namespace
+ *   must start with \Drupal\module_name. If it is defined by Drupal Core for
+ *   use across many modules, the namespace should be \Drupal\Core or
+ *   \Drupal\Component, with the exception of the global class \Drupal. See
+ *   https://www.drupal.org/node/1353118 for more about namespaces.
+ * - Plugin discovery requires particular namespaces for most plugin classes.
+ *   See the @link plugin_api Plugin API topic @endlink for more information.
+ * - Some classes have annotations added to their documentation headers. See
+ *   the @link annotation Annotation topic @endlink for more information.
+ * - There are project-wide coding standards for OO code, including naming:
+ *   https://drupal.org/node/608152
+ * - Documentation standards for classes are covered on:
+ *   https://www.drupal.org/coding-standards/docs#classes

Something like that.

Additionally, while I definitely don't want to duplicate documentation found elsewhere here, it'd be nice if we could point to a reference (off-site or otherwise) that explains what the heck these newfangledy words (class, interface and especially trait) are. Not just for D6/7 > D8 migrators, but for PHP devs in general who've come from a procedural background.

jhodgdon’s picture

Status: Needs work » Needs review
StatusFileSize
new2.56 KB

Good point. I adopted ... close to this ordering, see what you think.

Also added an @link to the php.net docs section on OO programming. Good idea.

I could make an interdiff but it's the same size pretty much as this patch... so just uploading the patch.

webchick’s picture

Status: Needs review » Fixed

Awesome, that looks great to me.

Since this was just a simple re-ordering of what was already there + the addition of a new link, I feel comfortable going ahead and committing this since it's already been at needs review for about a week.

Committed and pushed to 8.x. Thanks!

  • webchick committed 412fbfd on 8.x
    Issue #2216563 by jhodgdon: Fill in @defgroup/topic docs for Object...

Status: Fixed » Closed (fixed)

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