Following #1008166: Actions should be a module, we should clean up code documentation in the Actions module.

Posted by Lars Toomre on September 17, 2012 at 11:57pm

I am aware that most of this new module is moving around existing code. However, if this patch gets re-rolled again can we try to bring it up to D8 documentation standards since it now will be its own module?

The types of documentation problems I saw include:

a) Missing @param/@return type hints.

b) Some missing @param directives.

c) Some places can better wrap code to 80 characters.

The specific details are:

+++ b/core/modules/actions/actions.admin.incundefined
@@ -0,0 +1,276 @@
+ * @param $options

Can we add type hinting here please?

+++ b/core/modules/actions/actions.admin.incundefined
@@ -0,0 +1,276 @@
+ * @param $action
+ *   Hash of an action ID or an integer. If it is a hash, we are
+ *   creating a new instance. If it is an integer, we are editing an existing

Again can we add type hinting here e.g 'mixed'? Also this needs to explain that the default is NULL and what happens in that case.

+++ b/core/modules/actions/actions.admin.incundefined
@@ -0,0 +1,276 @@
+ * @param $orphaned
+ *   An array of orphaned actions.
+ */

Can we add array type hinting here?

+++ b/core/modules/actions/actions.admin.incundefined
@@ -0,0 +1,276 @@
+/**
+ * Removes actions that are in the database but not supported by any enabled module.

This needs to be reworked to fit within 80 characters.

+++ b/core/modules/actions/actions.api.phpundefined
@@ -0,0 +1,98 @@
+ * @return
+ *   An associative array of action descriptions. The keys of the array
+ *   are the names of the action functions, and each corresponding value
+ *   is an associative array with the following key-value pairs:

This should be rewrapped to fit better within 80 characters as well as adding a type hint.

+++ b/core/modules/actions/actions.api.phpundefined
@@ -0,0 +1,98 @@
+ *   - 'type': The type of object this action acts upon. Core actions have types

I am pretty sure that keys of a returned associative array should not be enclosed in single quotes for D8.

+++ b/core/modules/actions/actions.api.phpundefined
@@ -0,0 +1,98 @@
+ * @param $aid

For clarity, can we add type hinting here. Is this an integer or a string like a machine name?

+++ b/core/modules/actions/actions.api.phpundefined
@@ -0,0 +1,98 @@
+/**
+ * Alters the actions declared by another module.
+ *
+ * Called by actions_list() to allow modules to alter the return values from
+ * implementations of hook_action_info().
+ *
+ * @ingroup actions

Missing @param docblock describing what $actions variable is...

+++ b/core/modules/actions/actions.moduleundefined
@@ -0,0 +1,692 @@
+ * @param $context

Please add an array type hint here.

+++ b/core/modules/actions/actions.moduleundefined
@@ -0,0 +1,692 @@
+ * Processes actions_send_email_action form submissions.

Missing @return directive here explaining what in $params array.

+++ b/core/modules/actions/actions.moduleundefined
@@ -0,0 +1,692 @@
+ *   - 'recipient': E-mail message recipient. This will be passed through

Again, I believe the D8 standards do not require single quotes around these array keys.

+++ b/core/modules/actions/actions.moduleundefined
@@ -0,0 +1,692 @@
+ * Constructs the settings form for actions_message_action().
+ *

I think we are missing @param array $context here.

+++ b/core/modules/actions/actions.moduleundefined
@@ -0,0 +1,692 @@
+ * Action functions are declared by modules by implementing hook_action_info().

I think this explanation belongs after the one line summary and before @param line with blank line in between.

+++ b/core/modules/actions/actions.moduleundefined
@@ -0,0 +1,692 @@
+ * Constructs the settings form for actions_goto_action().
+ *
+ * @see actions_goto_action_submit()

Again, I think this is missing @param array $context with an explanation of what keys are expected.

+++ b/core/modules/actions/actions.moduleundefined
@@ -0,0 +1,692 @@
+ * Given the IDs of actions to perform, this function finds out what the
+ * callback functions for the actions are by querying the database. Then
+ * it calls each callback using the function call $function($context, $a1, $a2),
+ * passing the input arguments of this function (see below) to the

This should be rewrapped to better fit 80 characters per line with @param type hints added below.

+++ b/core/modules/actions/actions.moduleundefined
@@ -0,0 +1,692 @@
+ * This function contrasts with actions_get_all_actions(); see the
+ * documentation of actions_get_all_actions() for an explanation.
+ *
+ * @param $reset
+ *   Reset the action info static cache.
+ *
+ * @return
+ *   An associative array keyed on action function name, with the same format
+ *   as the return value of hook_action_info(), containing all
+ *   modules' hook_action_info() return values as modified by any
+ *   hook_action_info_alter() implementations.

This needs to be rewrapped for 80 characters and type hinting added.

+++ b/core/modules/actions/actions.moduleundefined
@@ -0,0 +1,692 @@
+ *   An associative array with function names or action IDs as keys
+ *   and associative arrays with keys 'label', 'type', etc. as values.

This needs to be rewrapped for 80 characters and the full list of expected array keys specified. Also could use a type hint.

+++ b/core/modules/actions/actions.moduleundefined
@@ -0,0 +1,692 @@
+ * @param $hash
+ *   Hash of a function name or action ID array key. The array key
+ *   is a key into the return value of actions_list() (array key is the action
+ *   function name) or actions_get_all_actions() (array key is the action ID).

This should be rewrapped to better fit 80 characters per line.

+++ b/core/modules/actions/actions.moduleundefined
@@ -0,0 +1,692 @@
+  // Must be a configurable action; check database.
+  $result = db_query("SELECT aid FROM {actions} WHERE parameters <> ''")->fetchAll(PDO::FETCH_ASSOC);

This comment needs to be reworked. Could be configurable action or not defined at this point.

+++ b/core/modules/actions/actions.moduleundefined
@@ -0,0 +1,692 @@
+ * @param $delete_orphans
+ *   If TRUE, any actions that exist in the database but are no longer
+ *   found in the code (for example, because the module that provides them has

This comment should start with '(optional) ' along with an explanation of what the default value is.

+++ b/core/modules/actions/actions.moduleundefined
@@ -0,0 +1,692 @@
+ * @param $function
+ *   The name of the function to be called when this action is performed.
+ * @param $type
+ *   The type of action, to describe grouping and/or context, e.g., 'node',
+ *   'user', 'comment', or 'system'.
+ * @param $params
+ *   An associative array with parameter names as keys and parameter values as
+ *   values.
+ * @param $label
+ *   A user-supplied label of this particular action, e.g., 'Send e-mail
+ *   to Jim'.
+ * @param $aid
+ *   The ID of this action. If omitted, a new action is created.
+ *
+ * @return

Type hinting here would be really helpful. Also $aid should start with '(Optional)'

+++ b/core/modules/actions/actions.moduleundefined
@@ -0,0 +1,692 @@
+ * @param $aid
+ *   The ID of the action to retrieve.
+ *
+ * @return
+ *   The appropriate action row from the database as an object.

Type hinting would be helpful here. Also an explanation of what happens in no $aid record found.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

RobLoach’s picture

Status: Active » Postponed
sun’s picture

Component: trigger.module » action.module
Status: Postponed » Active
Lars Toomre’s picture

Since documentation oriented patches tend to be assigned to @jhodgdon for commit, and Jennifer prefers to handle patches with just documentation separately from those that include type hinting, I have opened #1802070: Add missing type hinting to Action module docblocks to handle the type hinting aspect of the above comments.

Lars Toomre’s picture

Title: Clean up cruft in the Actions documentation » Clean up cruft in the Action documentation
Component: action.module » documentation
Status: Active » Needs review
FileSize
20.73 KB

Here is an untested patch addressing the issue summary (except for type hinting) as well as a full documentation review of this new module. Comments on this patch are welcome.

jhodgdon’s picture

For the record, if you're adding completely new param/return docs (that were previously missing), since that also requires reading the function to give them a thorough review, I have no problem with adding the types to them at the same time in the same patch.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks! I gave this a quick look... A few things are not conforming to our standards:

a) Form constructor functions - the standard is that we don't document $form, $form_state or @return for these. [action_admin_manage_form() has @return and shouldn't]

b) It's not necessary to leave a blank line between @see and @ingroup at the end of a doc block.

c) Class documentation first lines should have the same verb tense as functions [see LoopTest]

And I have a question about this:
d)

* @param object $entity
- *   An optional node entity, which will be added as $context['node'] if
- *   provided.
+ *   A node entity, which will be added as $context['node'] if that is empty.

This actually changes the meaning of the @param documentation, rather than being just a clean-up. Was that intentional? I haven't looked at the function body to verify... [change was made in two places]

jhodgdon’s picture

Status: Needs work » Postponed

Also, let's wait on continuing with this issue, because it's being worked on elsewhere:
#1431658: Clean up API docs for system module tests, A-D, including subdirectories

Lars Toomre’s picture

Status: Postponed » Active

Looks like #1431658: Clean up API docs for system module tests, A-D, including subdirectories still needs considerable work. Hence, returning this to active since it appears that there are only a few open items for this issue.

jhodgdon’s picture

Status: Active » Postponed

This patch will conflict with that one, and much of what is in this patch had already been done on that other issue. I'd like to keep this one postponed until that one gets finished, if you don't mind... or else make sure this patch doesn't cover the same stuff?

Lars Toomre’s picture

I am not sure why your request makes sense @jhodgdon. The focus of this issue is making the new D8 module conformant with D8 documentation standards.

jhodgdon’s picture

When we have issues with large patches, they are a pain to reroll when things get committed that conflict with them. That other issue was started before this code was split off into a new module, so it has been making changes to what is now in this new module, and has been following the code around as it moves around in the code base.

So, I'd like to get that patch finalized and committed before we make conflicting changes that will necessitate yet another reroll to that large patch. OK?

Lars Toomre’s picture

Quite frankly, if anyone wants to make the new Action module conformant with D8 documentation standards, they are welcome to pursue this issue further.

In the original issue, @sun and @catch stated that adding documentation fixes would be too difficult to review the move from an include file to a new Action module. Further, @sun decided that some documentation fixes were OK for the Ban module move, but for some unclear reason, such documentation changes would be inappropriate to the new Action module.

To address concerns about documentation, a follow up issue was created: This one!! Of course, this follow up issue has not received any attention like the original move issue. One might even reasonably conclude that documentation standards matter little more than lip service.

Nonetheless, after diligently creating a patch in #4, this issue is getting postponed because of something supposedly being proposed in #1431658: Clean up API docs for system module tests, A-D, including subdirectories.

I appreciate all of those involved with their concerns for proper procedures. However, the net result of this whole experience is my firm belief questioning why any core patch needs to conform with documentation standards. Of course, I might somehow be enlightened by this incredible process.

Lars Toomre’s picture

And just to be clear, both @sun and @catch, who were behind the decoupling of actions.inc to the new Action module, at least to my knowledge, have not bothered to confirm that the documentation is conformant (at least to some extent with D8 doc standards).

I am completely stumped about why the move was OK, but documentation fixes get first brushed off, first to a follow up issue, and then postponed.

My take away from the last few weeks is the original code review in #1008166-51: Actions should be a module has not had any effect and whatever was in the patch is simply OK.

I now know that such contributions to the Drupal review process are unwelcome and likely ignored. I have little interest in this ignore and postpone process.

webchick’s picture

I really don't think there are any grand conspiracies here.

1) Type-hinting is not a formal part of the documentation gate, and therefore is not currently something we hold back RTBC patches on. There is an issue to discuss this at #1792992: Are typed @param / @return part of the documentation gate? but consensus is not yet reached, so at the moment the existing gate (which does not include type-hinting) still stands.

2) When there are two patches that conflict with each other, the normal rule is "first to RTBC wins." However, it can be a good idea to postpone one on another for a variety of reasons: patch A is much further along and closer to get committed than patch B, patch A needs much more thorough reviews than patch B and so is much further off from RTBC, patch B is *much* harder to re-roll than patch A (esp. if it fixes a major/critical issue), etc.

3) Frankly, people are under absolutely no obligation to work on what you want them to work on. And they are even less inclined when your words and attitude imply they are lazy, belligerent, negligent, incompetent, or some combination of the above. If you find people aren't responding well to your requests for patch reviews, stop yourself and ask if the way you are conducting yourself in the issue queue might have something to do with that.

I don't have a horse in this race. Both patches deserve to be reviewed/committed, and no one is disputing that. But it looks like #1431658-26: Clean up API docs for system module tests, A-D, including subdirectories is a 127K patch, which focuses purely on API documentation changes and thus is much easier to review, much harder to re-roll, as well as less risky to commit. The patch here is only 27K and includes a wide range of changes, including docs fixes, coding standards fixes, etc. This is probably why it's being postponed in favour of the other. And rather than assuming sun and catch are liars who don't follow through on their commitments, how about assume they are busy frantically trying to get features into Drupal 8 while there's still time, and that patches like this will receive much more active review attention once we're at the point in the cycle that's designed specifically for this type of clean-up. Better yet, how about ask them how you can help them in their mission? That'll give them much more incentive to help you in return.

Lars, I think you do really thorough, meticulous work with documentation, and that's a huge asset to the team. But the way you treat other people is tearing the team apart. Please read http://drupal.org/dcoc and take the words to heart. "Come for the software, stay for the community" isn't just something we put on our website to feel good about ourselves. It's critical to a well-functioning core development team.

xjm’s picture

FileSize
30.98 KB
24.12 KB

Dec. 1 2012 to Sept. 2013 -- we can add docs

We can only add features until Dec. 1, in 8 weeks

Lars Toomre’s picture

@webchick Thanks for your thoughts. If and when this issue gets committed, I will respect that the event has occurred.

In the meantime, I will keep my thoughts to myself about the last paragraph of #14. I very much disagree, but I do not want to disrupt the supposed "core development" team.

jhodgdon’s picture

Status: Postponed » Needs work

That other patch got committed, so this one can be opened again. Setting status as per last patch review; also it will need a small reroll as the other patch conflicted with it in a couple of spots.

Lars Toomre’s picture

Thanks @jhodgdon. Someone else can drive this one home.

Apparently those involved with creating the new Action module do not care enough about documentation standards. Or if they do, they have yet to show up in this follow up issue.

webchick’s picture

The people making the Action module just moved the existing code from actions.inc to action.module. It was not part of their responsibility to *also* clean up the API docs in the process. That would be scope creep.

Albert Volkman’s picture

FileSize
18.41 KB

Re-roll of #4. Still needs work per the comments in #6.

dcam’s picture

Status: Needs work » Needs review

Setting status.

Status: Needs review » Needs work

The last submitted patch, 1787900-20-action-docs.patch, failed testing.

Albert Volkman’s picture

Status: Needs work » Needs review
FileSize
15.33 KB

Here we go, re-rolled and additional concerns (I think) addressed.

jhodgdon’s picture

Status: Needs review » Needs work

Can we take out all of the ridiculous "Defaults to ..." statements in this patch, which provide no information not already found in the function signatures?

Other than that, this patch looks fine... there are a few other things that could be improved (like "boolean" that should be "Boolean" in text, and in the LoopTest.php hunk at the end, describing what action ID the class is storing -- "an action ID" doesn't really tell me much about what that class member variable is being used for?)... but nothing I would probably hold up committing on.

xjm’s picture

Can we take out all of the ridiculous "Defaults to ..." statements in this patch, which provide no information not already found in the function signatures?

Uh, well, once upon a time when I was a novice writing documentation patches, the standard was to end the parameter description with what default value was provided and why. :) Has the standard changed in the past 18 months?

jhodgdon’s picture

If there's a reason to include the information, sure. But this has never been the standard that I'm aware of in general, and I think there are usually better ways to give the information than a "Defaults to NULL"... In this patch, I can't see anywhere it is really adding any information. Here are some examples:

+ *   (optional) The object that the action will act on: a node, user, or comment
+ *   object. Defaults to NULL.

Already says it's optional, so obviously you are allowed not to provide it, and it hardly matters what the default value is (that is something the code but not the caller would care about; in that case, look at the function sig along with the code).

+ *   (optional) Associative array containing extra information about what
+ *   triggered the action call, with $context['hook'] giving the name of the
+ *   hook that resulted in this call to actions_do(). Additional parameters
+ *   will be used as the data for token replacement. Defaults to NULL.

Ditto.

+ *   (optional) Passed along to the callback. Defaults to NULL.
 

Ditto.

+ *   (optional) A boolean indicating whether to reset the action info static
+ *   cache. Defaults to FALSE.

Would be a lot better to write "(optional) If set to TRUE, reset the static cache of action information."

+ *   (optional) The ID of this action. If omitted, a new action is created.
+ *   Defaults to NULL.

In this case, the text already says what happens if it is omitted, so the "Defaults to NULL" tells us nothing new and just wastes space.

etc.

webchick’s picture

Hm. I don't personally find those very offensive. When I'm reading docs, I'm reading docs. When I'm reading code, I'm reading code. Sometimes the two might be separated by a very large gulf of @return and @see and other things, or, on a site like http://api.drupal.org/, separated by totally different formatting, making moving my eyeball back and forth to gather up more information a bit jarring.

However, it is definitely duplicate information and can easily fall out of sync in said "gulfy" situations if people aren't careful. Is it helpful enough to counter-act the potential confusion if this happens? Couldn't say, and I don't really feel overly strong about it.

We could probably settle this by grepping and seeing what we do more often than not, and just continuing to do that. :)

xjm’s picture

Hm. I don't personally find those very offensive. When I'm reading docs, I'm reading docs. When I'm reading code, I'm reading code. Sometimes the two might be separated by a very large gulf of @return and @see and other things, or, on a site like http://api.drupal.org/, separated by totally different formatting, making moving my eyeball back and forth to gather up more information a bit jarring.

Yeah, I'd agree with this too, actually.

Albert Volkman’s picture

I could see the argument either way (duplicate content/falling out of sync vs readability). The pragmatic side of me says to just use the function's signature. Reduces work, and could possibly be parsed in a more useable way via a.d.o (being completely naïve to the limitations of the doc parsing)? I'm fine either way, however =)

Lars Toomre’s picture

My understanding was that the docblock should describe what a function/method does without needing to dig into/read the code at all. Hence, what the default value of a parameter is needed to be part of the documentation. This may have changed though in the last six months or so since I last worked on documentation issues.

jhodgdon’s picture

But "Defaults to NULL" adds exactly zero information in these cases. If you say (optional), it means the parameter is optional, and presumably if you don't supply it that is OK. Adding "Defaults to NULL" does not tell us anything at all, does it?

I am completely in agreement that in the case where the default value is more complicated or has some meaning beyond "it's not provided" when the @param says (optional), we should tell what the default value is. But in the case of "Defaults to NULL" it is IMO a waste of space/time, a burden to doc writers to set this as a precedent or standard, and a maintenance burden as well. Let's not make a habit of adding it to otherwise perfectly clear documentation.

I also don't agree that "reading the signature" is the same as "reading the code". On api.drupal.org, the function signature is right up there, and in IDEs it will be shown to you as well.

jhodgdon’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

These issues are a lot of work with very little tangible payoff, so I'm closing the rest of them as "won't fix". Your efforts on working on this issue were appreciated... it was just my fault for starting a task that was very difficult to get right.

Let's instead put our effort into fixing and reviewing documentation that is really unclear and/or wrong, and I hope that the people who worked on these issues are not afraid to jump into a more reasonable issue!