Problem/Motivation

  • hook_update_N() summaries appear in the update.php UI and are reused (e.g. in drush) to identify which update the function makes.
  • We do not have an example of hook_update_N() documentation in http://drupal.org/node/1354
  • "Implements hook_update_N()" is not really a useful function summary, but many people use this because it appears to be what's indicated in the Doxygen standards.

Proposed resolution

  • Document that the update hook summary should indicate what update or change the function makes.
  • The standard could use either an imperative form (like hook definitions) or third-person indicative (like other functions).

Proposed documentation (from #4):

For hook_update_N() implementations, there is a different standard, because the documentation's first line is displayed in the results section when update.php is run. So they are documented as follows:

/**
 * Add several fields to the {node_revision} table.
 *
 * Longer description can go here, if necessary.
 */
 module_name_update_7002() {
 }

Remaining tasks

Related issues:

CommentFileSizeAuthor
#2 pending.png22.89 KBxjm
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xjm’s picture

Issue summary: View changes

Updated issue summary.

jhodgdon’s picture

Status: Active » Postponed (maintainer needs more info)

If these do go to the UI, it would really be even better if the API was changed so that the strings were translatable, rather than being parsed out of the API documentation. Of course that would be d8 and beyond only, but we can't go back and impose new docs standards on d7 and previous anyway.

But anyway I don't see that happening in:
http://api.drupal.org/api/drupal/update.php/function/update_results_page/7
If it's just drush, then I'm not too worried about it.

So I'm not all that familiar with the update code... can you point me in the right direction, where the doc header is parsed and this is displayed in the update UI, if I missed it?

xjm’s picture

Status: Postponed (maintainer needs more info) » Active
FileSize
22.89 KB

It's in the detailed information when you expand the "pending updates" section. This function doc:

/**                                                                             
 * Add vocabulary defaults for all configured vocabularies.                     
 */
function taxonomy_access_update_7002() {

Is displayed like so:

pending.png

xjm’s picture

Oh, and it appears that the parsing happens in update_get_update_list().

Edit: I should also note that core has more-or-less informative docs for update hooks as far as I've seen, though with varying formats. But in contrib a lot of the time I see "Implements hook_update_N()" which doesn't really tell the user anything.

jhodgdon’s picture

Ah, I see! Thanks for the clarification and code pointer.

OK then, agreed, we should definitely make a standard. Proposal [to go into the hook implementations section http://drupal.org/node/1354#hookimpl , or right after that with a link to this special case]:

-----------
For hook_update_N() implementations, there is a different standard, because the documentation's first line is displayed in the results section when update.php is run. So they are documented as follows:

/**
 * Add several fields to the {node_revision} table.
 *
 * Longer description can go here, if necessary.
 */
 module_name_update_7002() {
 }

---------------

HOWEVER, I still think that if these doc strings are displayed in the UI then they should be translatable. Grabbing the one-line API documentation is not a good idea, really. I mean, would your average Drupal administrator who might not speak English find any of those English descriptions at all useful? But I guess that is a separate issue maybe...

jhodgdon’s picture

xjm’s picture

#4 looks good to me. And translating them does seem like it might be a good idea, if possible.

Couple other links:

jhodgdon’s picture

Wow, that doc page has no function header docs at all, eek! So we should add the header docs there too as a model, once agreed upon.

xjm’s picture

Status: Active » Needs review
Crell’s picture

If we are not going to be translating the description text, then the summary makes sense, and is what I thought we were already doing. :-) (One line summary of what the function does, longer description if needed.)

If we are going to be translating description text, I am going to put on a flame-retardant vest and suggest that update functions turn into update classes that implement a given interface; that interface includes title() and description() methods (or something), which return translated text, as well as an execute() method that is, roughly, the body of the function we have now.

Again, if no translation is necessary then I don't think objects are necessary here at this time.

sven.lauer’s picture

+1 on making this translatable in D8. And certainly +1 on documenting this in the standards (and the doc for hook_update_N()!) for D7.

Also, while I am definitely not a fan of objectifying things for objectification's sake (though I don't have a flame-thrower dedicated for the purpose), this seems like an obvious place to use classes, as here, clearly, things should be grouped together functionality-wise in an obvious way. All alternatives that come to mind smell badly (having a distinct hook_update_N_description()? *shudder* Having a hook_update_descriptions() that returns a map from update numbers to descriptions? *eww*).

Of course, with the change to PSR, this would mean a lot fo tinsy class files, but then again, these functions/classes really should only be loaded when needed, which one-class-per-file helps us do. So overall +1 to move to update classes.

And in any case, this pattern (which has surprised/bitten me in the past when I implemented my first hook_update_N()'s) is certainly an odd thing---I don't think there is any other place in core where doc headers are parsed and displayed to the user (I may be wrong).

webchick’s picture

Hm. Thought I already commented on this, but maybe it was a different issue...

Please confirm with some actual translators that it's desirable to make these strings translatable. I doubt that it is. We actually removed translatability from database schema description strings because translators noted that a) the strings were highly technical, and thus difficult for people to translate, and b) they were only viewable by basically one person per Drupal site which made translating them a waste of time.

xjm’s picture

Well, I think this issue is just about clearly documenting our existing standard so that the user-facing strings are meaningful, and the question of whether or not to translate (and how if so) them maybe should be a separate issue. (Wherein we can get feedback from people who actually do translating or use Drupal in sites other than English.) Edit: Though #11 makes it sound like the answer will probably be "no."

jhodgdon’s picture

Yes, there is already another issue for translatable (see comment #5 above).

jhodgdon’s picture

Issue summary: View changes

Right, stating the obvious.

xjm’s picture

Updated the summary with the proposed standard and the link to the other issue.

webchick’s picture

Title: No documentation standard for hook_update_N() summaries. » No documentation standard for hook_update_N() summaries [policy, no patch]
Status: Needs review » Reviewed & tested by the community

Seems fine. That's effectively our de-facto standard anyway.

jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

Given that everyone agrees this is a de facto standard, I went ahead and added it to:
http://drupal.org/node/1354#hookimpl

I also edited the examples on
http://drupal.org/node/150215
and made sure they all had one-line summaries as models.

I'd say this is fixed.

Gábor Hojtsy’s picture

Ok, so now is it not "required" to use 3rd person verbs, or is it not advised or is it forbidden (in update function first line phpdoc)? This is not really clear from the docs :/

jhodgdon’s picture

Status: Fixed » Needs review

That is a good question actually, and I guess we should discuss it.

We use 3rd person verbs for function docs because we're saying "[This function] Does some action.".

The purpose of these one-line descriptions though is not only to say what the function does for purposes of api.drupal.org, but also to say what is going to happen when someone runs update.php. As in, "[If you run this update, it will] Add something to your xyz table.".

So... yeah, we should adopt one or the other, and make it clear in the docs... Any thoughts on which?

Ah, let's see. What do we have in core? In drupal 8:

system.install:
Enable entity module.
Move from the Garland theme.

node.install
Rename node type language variable names.

etc. So it seems like our de-facto standard is what is in the docs now. Any thoughts?

xjm’s picture

I think the imperative/infinitive makes more sense in this case since it's telling the user what's being done. "Enables" doesn't really make sense because there's no implied subject that the user would know anything about. And, these are user-facing strings.

This actually isn't totally weird; our hook definitions have the same standard. However, I'm okay with either pattern (as per my summary).

Crell’s picture

Imperative makes more sense when it's shown to the user. They have no context other than "there's this string on the page that says what the code just did". Imperative makes sense there; "Enables" is just confusing.

jhodgdon’s picture

Status: Needs review » Fixed

OK, I think (a) existing core docs and (b) several people just now and (c) past reviewers of the standard are all in agreement with the standard staying as it is documented now. I will add a note about using the imperative form of the verb to 1354.

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

Anonymous’s picture

Issue summary: View changes

Updated issue summary.