Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
See the parent issue for problem motivation. This issue covers the following elements:
- Button
- DropButton - not sure as this is not technically a form element
- Operation - not sure as sthis is not technically a form element
- Submit
Proposed resolution
Document them....
Comment | File | Size | Author |
---|---|---|---|
#17 | interdiff-2486999-15-17.txt | 645 bytes | er.pushpinderrana |
#17 | 2486999-17-document-button-elements.patch | 4.08 KB | er.pushpinderrana |
#15 | 2486999-15-document-button-elements.patch | 4.08 KB | metzlerd |
#15 | interdiff-2486999-12-15.txt | 2.15 KB | metzlerd |
#12 | 2486999-12-document-button-elements.patch | 4.08 KB | metzlerd |
Comments
Comment #1
jhodgdonComment #2
metzlerd CreditAttribution: metzlerd as a volunteer commentedHere is a first draft. I took a stab at documentation a dropbutton even though your right, it isn't technically a form element. The more I use these render elements the more I think we need to think carefully about how we present the lists of elements in the API docs. Elements like Container and Details are not only for use in forms, but are most often used in forms. I'm not sure about Dropbutton It seems like it's most often used in as a column of a tableselect or a table, but I'm not sure how often it will be used in forms vs other controllers.
Anyway, here's the first stab.
Comment #3
jhodgdonThanks, looks pretty good! A few small suggestions:
supress => suppress
(typo)
Do you think we should mention here that #value is the text shown on the button? This is different from the standard meaning of the #value property for other elements, and is necessary in order to create a button that will actually work in a form.
I can see it in the usage example, but maybe we should explicitly document what the array elements are?
Missing the usual "Usage Example" header here.
punctuation:
(e.g., ...
Like in Button, I think we should document #value here.
Comment #4
metzlerd CreditAttribution: metzlerd as a volunteer commentedWorking on these. Regarding the links in the dropbutton.
Here's the relevant text from the Link render element:
Do you think we should copy this into dropbutton or note that the links are an array of "link" definitions. What the drop button does is use the link theme functions to render the array of links, but these links aren't true elements because they don't need '#type' => 'link'.
I could go for something like:
But I would probably have to add modifictions to the Link.php api docs in this patch to do it.
Do you have preferences on a way forward?
Comment #5
jhodgdonAh... hm... Yes, I think saying "See Link for additional info" (with your wording) makes the most sense. But. Is this using the link *theme* functions or the link *element* for rendering? Let's see... looks like it is using the theme function. So I think the proper thing to reference would be the links.html.twig template, which should have docs about the links... let's see if it does. Yes.
So really the dropbutton is just a wrapper for theme 'links__dropbutton' with a bit of wrapper prerendering, and I think rather than documenting #links specifically, we should point to links.html.twig, which has docs for several other properties as well as #links.
Hm. I'm looking at the prerender function in Dropbutton. It looks like it also supports a #subtype property, which if it is set, adds this to the #theme property. So if #theme was set to for instance the default of 'links__dropbutton', and #subtype is set to 'operations', it will make #theme into 'links__dropbutton__operations'.
Hope this makes sense.
I guess we should look through the other render elements and make sure there aren't any other properties being used by them that we should document, if you haven't been looking for these?
Comment #6
metzlerd CreditAttribution: metzlerd as a volunteer commentedHmmm... except the links.html.twig documentation documents #href and not #url. I assume this is generated somewhere along the way by the rendering preprocessing, but how do we make it make sense with the example, which asks people to specify routes (seems like the right thing to do)?
Comment #7
jhodgdonAh. Yeah, we should really point them at the template_preprocess_links() function, which documents the un-preprocessed information ...
So how about if we say something like:
This element uses the 'links' theme hook for rendering [say something about that it's actually links__dropbutton by default plus whatever is in #subtype]. See template_preprocess_links() for documentation on the properties used in theming; for instance, use element property #links to provide $variables['links'] for theming.
Not sure of wording... something like that?
Comment #8
metzlerd CreditAttribution: metzlerd as a volunteer commentedBy the way, regarding #subtype. I am really wondering whether to document this at all. The Operations element doesn't use this, but rather just sets the #theme function directly. I would think that if we wanted to drive people toward the operations styling, then we'd want to direct them to the Operations element? I did a search through core and #subtype is never used. This feels a bit like the FieldGroup element to me in terms of documenting something that maybe shouldn't have been implemented to begin with?
Here's the patch with the revisions so far.
Comment #11
jhodgdonOK, this looks good. One nitpick:
punctuation: After e.g., you need a comma. Or better yet (since e.g. and i.e. are confused/misused nearly always in Drupal API docs) just write out "for example,".
And I still think we should document #subtype. The element explicitly uses it, and it's specific to this type of element. I still like my suggestion in #7. Specific suggestion:
By default, this element sets #theme so that the 'links' theme hook is used for rendering, with suffixes so that themes can override this specifically without overriding all links theming. If the #subtype property is provided in your render array with value 'foo', #theme is set to links__dropbutton_foo; if not, it's links__dropbutton_foo; both of these can be overridden by setting the #theme property in your render array. See template_preprocess_links() for documentation on the other properties used in theming; for instance, use element property #links to provide $variables['links'] for theming.
And then in Operations maybe mention that #subtype is given a value by default?
Comment #12
metzlerd CreditAttribution: metzlerd as a volunteer commentedOk. I have made the changes. Not sure if we should remove what I did or not. Take a read and tell me what you think. Talk about $variables and stuff feels a bit like theme internals rather than form api stuff. I'm wondering if it sounds confusing.
Comment #13
metzlerd CreditAttribution: metzlerd as a volunteer commentedAnother minor point about Operations. It doesn't actually use #subtype. It sets #theme directly, so it's not accurate to say that it gives #subtype a value by default. #subtype only appears to only set #theme based on a naming convention and does nothing else that I can discern, which is why I wasn't sure about documenting it. I'm basically ambivalent about documenting it, so included this based on that.
Comment #14
jhodgdonLooking good!
A few questions/comments remain:
Um... This is confusing to me. What are "sections of the form validations"? I don't understand what this is saying.
Whoops, I had two typos in #11 that you copied into here. I think if there is no #subtype, it's links__dropbutton, and if foo is provided, I think it's links__dropbutton__foo (with a double-underscore). I hope so anyway.
Comment #15
metzlerd CreditAttribution: metzlerd as a volunteer commentedYes, I was a bit dubious when I copied that snippet about "sections" from another section of the docs. I've reworded it in a way that I hope makes more sense. If it still doesn't make sense, let me know and we can talk about trying something else.
Comment #16
jhodgdonMuch better! One small typo and I think we're done here:
fail -> fails
in the last line (it is saying "... when validation ... fails.")
Comment #17
er.pushpinderrana CreditAttribution: er.pushpinderrana as a volunteer and at Publicis Sapient for Publicis Sapient commentedComment #18
jhodgdonThanks! I think metzlerd would have finished up this issue, but that's OK.
Comment #19
metzlerd CreditAttribution: metzlerd as a volunteer commentedYes, but always happy for the help. Thanks.
Comment #20
jhodgdonTagging for "it's OK to commit now". Just API docs.
Comment #21
alexpottCommitted 78aba37 and pushed to 8.0.x. Thanks!