On http://api.drupal.org/api/drupal/core%21includes%21common.inc/function/d... :
> Sorts a structured array by 'weight' key (no # prefix).
On http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_sor... :
> Function used by uasort to sort structured arrays by weight, without the property weight prefix.
In both cases, what's the prefix thing about?
This function doc should say, in approximate order:
- this is a callback for uasort() (which I presume needs the () so it can be rendered as a link to PHP docs)
- it sorts arrays where each item (itself an array) has a ['weight'] property
- if an element doesn't have that property, its weight it taken as being 0
Also, now that API has string references, I don't think the D8 docs need to explicitly list the functions that make use of this.
Comments
Comment #1
jhodgdonThanks for this report! Some thoughts:
- The note about the # prefix is there so that you don't think you can use it to sort form elements by their '#weight' array element. Obviously, that was a bit confusing, so let's get that reworded.
- I agree that the list in D8 of some of the functions that use this callback is not really necessary. How about we just change it to say "Callback for uasort() used in various functions.".
- I also agree the 0 default weight should be mentioned in the documentation.
- I also agree that the documentation could be better written in general.
- The documentation should also use the term "element" to refer to an array value that corresponds to a particular key (I think it is using "key" incorrectly in a couple of places).
So let's start with a D8 patch to clean up the documentation there, and then port to D7.
Comment #2
marcin.wosinek CreditAttribution: marcin.wosinek commentedHere is patch.
Comment #3
jhodgdonLooks pretty good! There's a spot of English grammar and spelling that needs to be fixed:
The second sentence should say:
For items without a 'weight' element, a default value of 0 will be used.
Also I think in the first line, it shouldn't say "no # prefix is needed" -- that is not really clearing up the confusion I think. I think it should say something that *does* clear up the confusion, in a new paragraph. Something like:
Note that the sorting is by the 'weight' array element, not by the render element property '#weight'.
Comment #4
marcin.wosinek CreditAttribution: marcin.wosinek commentedChanged after feedback from #3.
Comment #5
jhodgdonBetter! Two little fixes and I think it will be ready:
- default is still misspelled.
- The first line needs "the" (... by the 'weight...)
Comment #6
jhodgdonAlso check for spaces at the end of lines.
Comment #7
marcin.wosinek CreditAttribution: marcin.wosinek commentedWith feedback from #5
Comment #8
joachim CreditAttribution: joachim commentedLooks good to me.
Comment #9
jhodgdonThanks! Committed to 8.x. Patch doesn't apply to 7.x, so we need a reroll/port.
Comment #10
marcin.wosinek CreditAttribution: marcin.wosinek commentedPorted.
Comment #11
jhodgdonLooks good, thanks! Committed to 7.x.