Problem/Motivation

From #1317620: Clean up API docs for includes directory, files starting with D-G. There are undocumented parameters in many of the files updated by that patch.

Proposed resolution

Add documentation for all parameters in these files.

Remaining tasks

Followup issues

  • Documentation of pre-render and other Render API stuff, especially in form.inc?

Miscellaneous

  • month_map uses drupal_static() unnecessarily. The number of months in a year isn't going to change when someone clears the cache. Make it a regular static.
  • weight_value() has a parameter misleadingly named $form. It should probably be $element.
  • To reference or not to reference, that is the question. Whether it is nobler in the mind to update values just upon return, or add an ampersand to things, and by passing, change them. (E.g., _form_element_triggered_scripted_submission() takes $form_state by reference but doesn't actually change anything, whereas other functions don't.)
  • form_process_checkboxes() only accepts as a parameter. (Unlike other similar functions, it does not accept <code>$form_state.)
CommentFileSizeAuthor
#12 d-g-params-1542800-12.patch14.59 KBxjm
#12 interdiff-12.txt1.32 KBxjm
#3 d-g-param.patch14.64 KBxjm

Comments

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Status: Active » Needs review
StatusFileSize
new14.64 KB
xjm’s picture

Note that, as in #1326456: Add missing @param in includes A-C, plus other corrections to some docblocks, I added datatypes for the new parameters because it's necessary to look the function up anyway to see how the parameters are used.

xjm’s picture

To review this patch:

  1. Review only the changed lines (lines with a + or - in front of them, not the other lines which are provided for context.)
  2. Check that each parameter block is formatted correctly per http://drupal.org/node/1354#functions, including the correct indentation and the correct whitespace between the parameter list and other parts of the docblock.
  3. Check that the parameters are identified correctly. For example, if the function signature is function($foo_bar), the parameter should be listed as $foo_bar in the docblock, not $foobar.
  4. Check that all parameters are documented, unless our standards explicitly specify omitting them (as with form constructors).
  5. Check that the parameters are in the order specified in the function signature.
  6. Read each parameter description and make sure that it is grammatically correct, clear English, with proper capitalization, punctuation, etc. (Each parameter description should form a complete English sentence if the words "This parameter is..." were to be added to the beginning, but those words should not be included in the docblock.) Keep an eye out for typos.
  7. Look up each function in the patch on api.drupal.org (D8). Read the function carefully and ensure that the parameter description properly documents how the parameter is used.
  8. Look at the datatype documented for each parameter. Make sure the types correspond to the allowed types at http://drupal.org/node/1354#param-return-data-type.
  9. Make sure all possibilities for the parameter are documented; for example, if the function optionally accepts a NULL value for a string parameter, then it should be documented as string|null.
  10. Also check the function's callers and string references (linked on api.d.o) and make sure the values being passed to the function are in the datatypes specified.
  11. Apply the patch to your local repository, and check that no other functions in these files are missing parameter documentation.
  12. Document what you reviewed and what you found specifically in your review comment.
hosef’s picture

I have not looked to see if there are any other comment blocks that need to be modified, however I did find a few things that should be changed in the comment blocks that were modified by this patch.

In form.inc:

'form_process_checkboxes' only accepts '$elements', it does not accept '$form_state'

before 'form_process_autocomplete', it should say '@param array $element' instead of '@param $element'

In gettext.inc:

before '_locale_import_tokenize_formula', it should say '@param string $formula' instead of '@param $formula'

Everything else looks good so far, and the patch applied cleanly.

hosef’s picture

I also found a few places where variable references were made in some function when the accepted properties were defined. It seems to me that doing so may trip up novice programmers who don't expect it and are trying to figure out where the value of the variable is being changed, hence we should probably just update the values at the end of the functions to promote ease of debugging, even though it will make a few functions longer.

xjm’s picture

I also found a few places where variable references were made in some function when the accepted properties were defined.

Could you clarify this? Do you mean the chaos of random passing by reference versus not? I have that as a point for followup in the summary. Or something else?

xjm’s picture

Status: Needs review » Needs work

Marking NW for #6. Thanks @hosef for the review!

xjm’s picture

Issue summary: View changes

.

xjm’s picture

Status: Needs work » Needs review
StatusFileSize
new1.32 KB
new14.59 KB

'form_process_checkboxes' only accepts '$elements', it does not accept '$form_state'

Weird... this is rather different from the FAPI element functions. I'll add this to the summary.

before 'form_process_autocomplete', it should say '@param array $element' instead of '@param $element'

I was debating whether this was scope creep, but I agree it's a bad idea for the docblock to be inconsistent.

Attached patch corrects the issues identified in #6.

xjm’s picture

Status: Needs review » Needs work
+++ b/core/includes/form.incundefined
@@ -2857,7 +2911,14 @@ function form_process_password_confirm($element) {
+ * @param array $element
+ *   An associative array containing the element structure, including its
+ *   properties and children.
+ * @param array $element_state
+ *   An associative array containing the current state of the form element.
+ *   Passed by reference.

@@ -2965,6 +3030,10 @@ function form_process_date($element) {
+ * @param array $element
+ *   An associative array containing the date element structure, including
+ *   its properties and children.

@@ -3532,6 +3634,13 @@ function form_process_machine_name($element, &$form_state) {
+ * @param array $element
+ *   An associative array containing the machine name element structure,
+ *   including its properties and children. Passed and updated by reference.
+ * @param array $form_state
+ *   An associative array of data for the current state of the form that
+ *   contains this element. Passed by reference.

@@ -3915,6 +4027,13 @@ function theme_email($variables) {
+ * @param array $element
+ *   An associative array containing the email element structure, including its
+ *   properties and children. Passed and updated by reference.
+ * @param array $form_state
+ *   An associative array of data for the current state of the form that
+ *   contains this element. Passed by reference.

@@ -3995,6 +4114,13 @@ function theme_range($variables) {
+ * @param array $element
+ *   An associative array containing the number element structure, including
+ *   its properties and children. Passed and updated by reference.
+ * @param array $form_state
+ *   An associative array of data for the current state of the form that
+ *   contains this element. Passed by reference.

@@ -4075,6 +4201,13 @@ function theme_search($variables) {
+ * @param array $element
+ *   An associative array containing the url element structure, including its
+ *   properties and children. Passed and updated by reference.
+ * @param array $form_state
+ *   An associative array of data for the current state of the form that
+ *   contains this element. Passed by reference.

So, there is a case to be made that those do not need to be documented, since the parameters are always the same:

  • None of the element type validation handlers in form.inc have parameter documentation, and maybe it makes sense to be consistent with form element validation handlers generally for specific elements.
  • Two are inconsistently named and documented, date_validate() and password_confirm_validate(). (The latter also has weird parameter names.)
  • Some get the $element parameter by reference and others don't. @jhodgdon and I weren't sure about this (and I think @hosef is also referring to this above).
  • The form process callbacks are similarly inconsistent. Some have currently have parameter documentation and others do not; the parameters are inconsistent; etc.
xjm’s picture

Status: Needs work » Needs review

darn you dreditor

Niklas Fiekas’s picture

Mhh ... I see no reason to repeat parameter docs for process and element validation functions. That basically increases the noise without adding any information. Whereas if the docs actually are specific to the element - like they are for the variables array on theme functions - that's really helpful (positive example: #1540174: Some attributes not allowed for the new HTML5 input elements).

xjm’s picture

sun has filed: #1552308: Consistently make all form callbacks take $element by reference.

Though it looks like the range validation callback actually needs to be a value function.

I'll look for some more references on the documentation question.

hosef’s picture

Status: Needs review » Needs work

Ok, here are the functions that I think still need to be looked at

'function _db_create_keys_sql($spec)' on line 667 of database.inc
'function drupal_form_submit($form_id, &$form_state)' on line 691 of form.inc
'function form_type_checkbox_value($element, $input = FALSE)' on line 2285 of form.inc
'function form_process_checkboxes($element)' on line 3268 of form.inc
'function form_process_weight($element)' on line 4301 of form.inc
'function _form_set_class(&$element, $class = array())' on line 4547 of form.inc

This issue got a lot easier to review once I figured out what the 'D-G' in the issue title meant. :P

xjm’s picture

Assigned: xjm » Unassigned
xjm’s picture

Issue summary: View changes

Updated issue summary.

jhodgdon’s picture

Status: Needs work » Closed (won't fix)

I'm closing very old coding standards fixup issues. They are being addressed on other issues mostly.