This issue should fix these documentation problems with form/render elements:
a) The \Drupal\Core\Render\Element\Select element class has a bunch of documentation about properties on its processSelect() method, in the $element parameter.. And it has some property documentation on its main class. They should be removed from the method and put onto the main class.
b) We also need to make sure in particular that #multiple and #size properties are documented in the main class doc block on the Select element.
c) There are several other form/render element classes (in the same namespace) that are lacking documentation for the #size property:
Date
Email
Number
Password
PasswordConfirm
Select (current scope of this issue)
Table
Tel
Url
These all need documentation similar to what is in the Textfield class for the #size property.
| Comment | File | Size | Author |
|---|---|---|---|
| #38 | 2721725-38.patch | 8.06 KB | vinay15 |
| #26 | interdiff-2721725-22-26.txt | 745 bytes | vinay15 |
| #26 | D8-select-form_input-2721725-26.patch | 673 bytes | vinay15 |
| #22 | interdiff.txt | 848 bytes | snehi |
| #22 | 2721725-20.patch | 674 bytes | snehi |
Comments
Comment #2
pushpinderchauhan commentedPlease review.
Comment #3
pushpinderchauhan commentedComment #4
kevin p davison commentedDoes "Boolean" require capitalization? I'd recommend "boolean."
Comment #5
zerbash commentedI agree. Patch and interdiff attached.
Comment #6
ckrinaHi @zerbash, I reviewed the patch and it is OK. Thank you for changing the capital letter.
But I was wondering why you changed also the other line in your commit. Could you explain it?
from:
* - #size: The size of the select box in characters.to:
* - #size: The width of the textfield (in characters).Comment #8
zerbash commentedI copied the first half of the definition for the #size attribute for the select element from the D7 Form API Reference page. However, in confirming to see if that was accurate, I rendered this element out of the context of a form: Setting #size to an integer greater than one changes the select to a multiselect and ADDS that number of SPACES to the end of the options list. So maybe there's another issue?
Comment #9
zerbash commentedIn the context of a form:
Out of the context of a form:
Comment #10
Sonal.Sangale commentedThe documentation of #multiple and #size is appropriate in latest patch. Hence changing the status of this issue to Needs Review.
Comment #11
jhodgdonThanks!
This still needs some work though...
Um, you can always select 1 option, right? So this description seems confusing to me.
It is not a text field, so can this also be updated?
Comment #12
snehi commentedGiven it a try.
Comment #13
jhodgdonThanks! Looking better, but still needs some work:
So it's fairly clear from the name #multiple that TRUE means multiple items can be selected and FALSE means only 1 item can be selected... but why not just say that, instead of this kind of hard-to-parse description?
Is that really what #size is for a select element? If this gets put into the size attribute for the select HTML element (and I think it does), I think it is actually the number of elements displayed? Someone needs to check on this.
Comment #14
vinay15Comment #15
vinay15Yes jhodgdon, size specifies the number of elements displayed. I have tried to update it.
Comment #16
vinay15Comment #17
jhodgdonCan you please just say "TRUE if ...; FALSE if ..." because again, saying "Indicates whether one or more options can be selected" is not clear on what TRUE means and what FALSE means. Thanks!
Comment #18
vinay15Thank you very much Jennifer. I have updated the patch.
Comment #19
jhodgdonThanks, better! But:
This is still not correct. FALSE means only one option *can be selected*, not that only one *is selected*. Similarly for TRUE.
And here... we can omit "in a select list". This is all related to a select list.
Comment #20
ashishdalviComment #21
ashishdalviThanks @jhodgdon.
Worked on your suggestions. Please review.
Comment #22
snehi commentedDone.
Comment #23
jhodgdonTwo patches -- @snehi, this issue was assigned, best to leave it to the person it was assigned to, thanks!
That aside, I like the wording in the patch in #22 slightly better -- I think the word "only" is helpful.
But two small things to fix:
This line goes over 80 characters.
options -> option
Comment #24
vinay15Comment #25
snehi commented@Jhodgdon Sorry for that. But when i was uploading the patch the uploading time was same for the both patches may be a lag of few seconds.
Comment #26
vinay15Hi Jennifer, I have updated the patch.
Comment #27
vinay15Comment #28
jhodgdonLooks fine, thanks!
Comment #29
xjmThanks everyone. I checked and confirmed that
Selectdirectly extendsFormElement, which does not define either of these properties: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...I also checked the rest of the Select code for how these are used.
#multipleis currently documented on Select::processSelect(). So, we should decide how to consolidate that documentation.At first I was confused by
#sizebecause there is only a reference tosize(no#), but turns out that was within an Element::setAttributes(), which appends the#).However, it actually looks like the
Textfielddocumentation for#sizeis an outlier:For comparison, here's a similar search for the
#multipleproperty (irrelevant results removed):So I think we need to look a bit more closely on how we document these two element properties. To avoid too much scope creep, perhaps we rescope this and split it into two issues: One for documenting
#sizein a consistent way across the elements that support it (including checking for others that are missing it), and a second similar issue for#multiple.Comment #30
jhodgdonUm, I'm confused. It looks like the #size element is documented all over the place. For textfields, #size is the width. For selects, it's the number of elements in the list. That is just how HTML is -- the size attribute has multiple meanings depending on what type of HTML element it's on, and our Element classes are correspondingly different. I don't see what needs to be done here to change the patch?
And for multiple, what other elements support it? It looks like three have the docs. In the old 7.x FAPI reference, only select and tableselect had #multiple attributes; those are documented here.
So... I don't think there is anything more to do here. Select was missing docs; this patch adds them. #size is not the same for Select as others, so the docs are different. It doesn't look like anything else is missing docs... please correct me if I'm wrong?
Comment #31
jhodgdonAnd I don't see it as a problem to have the docs for #multiple in two places. We want it in the main class so that users of Select have one place to look for docs. And the method that actually does the processing, why shouldn't it also document what it is doing?
Comment #33
jhodgdonThere's the Migrate random test failure again...
Comment #34
xjmThanks @jhodgdon. The following elements specifically document what
#sizemeans for them:But all these don't:
I'm suggesting we change the scope of this issue to address that, rather than making a similar change in all those places and needing to check back to see if we were consistent. After all, this issue is already drawing on the documentation for Textfield.
I agree it should, but what we shouldn't do is have different documentation for it in two places on the class, which is currently what this patch introduces. (Could just be a small change; I think we could address that by simply adding a "See
processSelect()" or something, or vice versa.)Comment #35
xjmRelated: It looks like there are a lot of these issues to add missing render element property documentation (thanks especially to @joachim and @jhodgdon for working on all these!). So far though none that I've had a chance to look at refer to any overall meta or plan. Is there such a resource, and if not, can we create a meta issue? Several questions came up in the process of reviewing a few of these and it would help to have a big picture issue where we can discuss them so we don't have the same questions in multiple places. Thanks!
Comment #36
xjmBTW, the Migrate random fail issue is an existing critical: #2724871: Random failure in \Drupal\migrate_drupal_ui\Tests\d7\MigrateUpgrade7Test
Comment #37
jhodgdonOK...
Regarding a meta, we had a meta to get basic documentation on all the form elements. It is still in progress, with a child issue or two still open:
#2486967: [meta] Move/Create Form Element Documentation
Then we have a postponed follow-up issue to check what still needs to be done against the old FAPI reference:
#2603810: [meta] See what else needs updating in Form/Render element docs
but that hasn't been started, since the parent meta hasn't been finished yet. So, the issues exist. Lack of progress due to no one working on them. (I would have time to do them, and many more docs patches, but if I do docs patches, or any other patches for that matter, no one reviews them, so I mostly stick to reviews, so that at least others who do patches get a review.)
Regarding #size, I agree we could expand the scope of this issue to include the other elements, even though #size is quite different for the rest of the elements than what it means on Select, as discussed above. If you insist. I'd prefer to just leave this as it was, but I'm not the person who decides if issue scope is OK.... so whatever. I seem to always be making the wrong scope decisions.
Regarding the processSelect() method, yes let's get rid of the docs there and move them all up to the main Select class.
Updating the issue summary.
Comment #38
vinay15Updated patch as per updated Issue Summary.
Comment #40
jp.stacey commentedThanks @Vinay15: I can confirm that the patch on #38 (a) addresses the three requirements in the description on this ticket and (b) applies cleanly to 8.3.x HEAD.
Comment #41
jp.stacey commentedComment #45
catchCommitted/pushed to 8.3.x and 8.2.x, thanks!
I cross-committed with the bot marking this needs work, but it's docs-only so shouldn't be the cause of real failures anyway.