Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
documentation
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
7 Feb 2014 at 20:54 UTC
Updated:
29 Jul 2014 at 23:21 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
jhodgdonReference: https://drupal.org/node/2117411
Comment #2
jhodgdonComment #3
eojthebraveI took a stab at re-writing this.
Comment #4
jhodgdonThanks! This looks mostly excellent! A few proofreading-type things to fix:
a) Whenever you refer to a namespaced class in docs, it needs to start with \. For example:
in both lines it should be \Drupal\Core\....
b) Pet grammar/puncutation peeve [I had a postdoc advisor who was a stickler for this, "some years ago"]:
You either need to change "which" to "that", or precede it by a comma. The only exception would be in "of which".
c)
In that 3rd line, I think a comma after "forms" would be helpful? Or a semicolon, which would let you make a complete sentence for the 2nd clause, and completely remove the "of which" there? Check the rest of the patch too -- a couple of other spots.
d)
Oxford comma -- in a list of "a, b, and c" or "a, b, or c", we require a comma before the "and" or "or" [here, the "and" on the 2nd line]. Also do you think a comma would be helpful before "such as" in the first line?
e)
I'd make these into one paragraph? Also, in the example code that follows, there is no call to ->getForm(). I think I'd just add a line (after a blank line) at the end with that call, rather than just explaining it in the following paragraph, or else move the example up and preface it with "Here's an example of a form class", because it doesn't illustrate ->getForm().
Actually... Maybe it would be good to move it quite a bit up.... Up here:
How about leaving FormBuilder out of the text there, and just talking about form classes first, and then giving the form class example? Then you can start a new section and talk about the FormBuilder and ->getForm() stuff separately, instead of trying to merge them into one example and discussion? Most people don't really need to know about the FormBuilder class anyway -- they just need to know how to make a form class and how to call getForm() to display it, right? And many uses don't actually need to know about getForm(), because they'll be using a FormController class as the page controller...
f) By the way you can put section headers into API docs now, and make links to them, with @section, @subsection, and @ref:
https://drupal.org/node/1354#section
https://drupal.org/node/1354#ref
Could be useful?
g)
A couple of commas would make this long sentence easier to parse? Or separate into several sentences?
h)
You really don't like commas, do you? :) I would suggest one after Alternatively here.
This really would be a good place for a @section. How about one section about form classes, one about building forms, and one about form controllers?
i)
This doesn't explicitly say it's an example that should go into a routing.yml file, maybe it should? Also, I believe if you do this, you need to make ExampleForm extend a different class (a form controller class), not just BaseForm? Check on this...
Comment #5
tim.plunkettYou should include a namespace, like
namespace Drupal\mymodule\Form;The indentation is off here. the FAPI keys need 1 more space, the ); needs one less, and the return $form needs one more.
This is actually incorrect. The form ID from getFormId() is used for the actual resulting HTML, as well as for hook_form_FORM_ID_alter. getForm only takes string names now for legacy non-OO form functions, and that will be removed.
The preferred argument would be the classname itself, as a string (
'Drupal\mymodule\Form\ExampleForm'). In very special cases, you may need to manipulate the form object before buildForm is called, in which case you can do$form_object = new \Drupal\mymodule\Form\ExampleForm($something_special); $form_builder->getForm($form_object);I think based should be passed
This must be
public function buildForm(array $form, array &$form_state, $extra = NULL) {The = NULL and array typehints are mandatory.
Not true, it's fine as is. You would only need something special if you were using
_contentfor some reason, but the purpose of_formin the routing yaml is to make this work with no modifications needed to the classComment #6
eojthebraveThanks for the review and the great feedback. I've done my best to incorporate all of it into the patch. Tim, I think the bit about advanced methods for form retrieval are probably better suited for https://drupal.org/node/2117411 than form.inc. I'll work on getting your feedback added there next. As well as updating that page which has the same wrong usage of $form_builder->getForm().
Comment #7
eojthebraveThere was a missing use statement. This adds use Drupal\Core\Form\FormBase; to the code example. Now I think this is really ready to go. :)
Comment #8
jhodgdonMuch better, thanks!
A few minor notes:
a) Normally, we don't want a blank line after a @section line.
b) Normally, after a : we don't want a blank line.
c) Extra comma here after validateForm(), and I think it needs one after submiForm() instead:
d) Colon after "method" instead of ending in . -- or maybe say "For example:
e) same as (d) -- colon:
f) I think this needs some indentation:
(path and defaults should be indented two spaces, right?)
Other than those minor fixes, I think this looks very good!
Comment #9
eojthebraveThanks for the feedback. Here's the cleaned up version.
Comment #10
tim.plunkettTechnically it's fine, I'll leave it to @jhodgdon to sign off on the docs part. Thanks @eojthebrave!
Comment #11
jhodgdonExcellent work! Docs part is good too.
Comment #12
jhodgdonThanks again! I found a couple of lines that were longer than 80 characters, and fixed the wrapping at commit time. Committed to 8.x.