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....

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

metzlerd’s picture

Status: Active » Needs review
FileSize
3.23 KB

Here 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.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks, looks pretty good! A few small suggestions:

  1. +++ b/core/lib/Drupal/Core/Render/Element/Button.php
    @@ -16,6 +16,21 @@
    + *   an empty array to supress all form validation errors.
    

    supress => suppress
    (typo)

  2. +++ b/core/lib/Drupal/Core/Render/Element/Button.php
    @@ -16,6 +16,21 @@
    + *   '#value => $this->t('Preview'),
    

    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.

  3. +++ b/core/lib/Drupal/Core/Render/Element/Dropbutton.php
    @@ -10,6 +10,25 @@
    + * - #links: An array of links to actions.
    

    I can see it in the usage example, but maybe we should explicitly document what the array elements are?

  4. +++ b/core/lib/Drupal/Core/Render/Element/Dropbutton.php
    @@ -10,6 +10,25 @@
    + * @code
    

    Missing the usual "Usage Example" header here.

  5. +++ b/core/lib/Drupal/Core/Render/Element/Submit.php
    @@ -13,6 +13,21 @@
    + *   the object and method name (e.g. [ $this, 'methodName'] ).
    

    punctuation:

    (e.g., ...

  6. +++ b/core/lib/Drupal/Core/Render/Element/Submit.php
    @@ -13,6 +13,21 @@
    + *   '#value' => $this->t('Save'),
    

    Like in Button, I think we should document #value here.

metzlerd’s picture

Working on these. Regarding the links in the dropbutton.

Here's the relevant text from the Link render element:

   *   - #title: The link text to pass as argument to _l().
   *   - #url: The URL info either pointing to a route or a non routed path.
   *   - #options: (optional) An array of options to pass to _l() or the link
   *     generator.

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:

An array of link definitions.  See \Drupal\Core\Render\Element\Link 
for additional info on properties. 

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?

jhodgdon’s picture

Ah... 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?

metzlerd’s picture

Hmmm... 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)?

jhodgdon’s picture

Ah. 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?

metzlerd’s picture

Status: Needs work » Needs review
FileSize
1.75 KB
3.44 KB

By 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.

Status: Needs review » Needs work

The last submitted patch, 8: 2486999-8-document-button-elements.patch, failed testing.

Status: Needs work » Needs review
jhodgdon’s picture

OK, this looks good. One nitpick:

+++ b/core/lib/Drupal/Core/Render/Element/Submit.php
@@ -13,6 +13,22 @@
+ *   the object and method name (e.g. [ $this, 'methodName'] ).

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?

metzlerd’s picture

Status: Needs review » Needs work
FileSize
1.71 KB
4.08 KB

Ok. 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.

metzlerd’s picture

Another 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.

jhodgdon’s picture

Looking good!

A few questions/comments remain:

  1. +++ b/core/lib/Drupal/Core/Render/Element/Button.php
    @@ -16,6 +16,23 @@
    + * - #limit_validation_errors: An array of form element keys that reference the
    + *   sections of the form validations that will block form submission. Specify
    

    Um... This is confusing to me. What are "sections of the form validations"? I don't understand what this is saying.

  2. +++ b/core/lib/Drupal/Core/Render/Element/Dropbutton.php
    @@ -10,6 +10,37 @@
    + * 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
    

    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.

metzlerd’s picture

Status: Needs work » Needs review
FileSize
2.15 KB
4.08 KB

Yes, 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.

jhodgdon’s picture

Status: Needs review » Needs work

Much better! One small typo and I think we're done here:

+++ b/core/lib/Drupal/Core/Render/Element/Button.php
@@ -16,6 +16,23 @@
+ * - #limit_validation_errors: An array of form element keys that will block
+ *   form submission when validation for these elements or any child elements
+ *   fail. Specify an empty array to suppress all form validation errors.

fail -> fails
in the last line (it is saying "... when validation ... fails.")

er.pushpinderrana’s picture

Status: Needs work » Needs review
FileSize
4.08 KB
645 bytes
jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! I think metzlerd would have finished up this issue, but that's OK.

metzlerd’s picture

Yes, but always happy for the help. Thanks.

jhodgdon’s picture

Issue tags: +rc eligible

Tagging for "it's OK to commit now". Just API docs.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 78aba37 and pushed to 8.0.x. Thanks!

  • alexpott committed 78aba37 on 8.0.x
    Issue #2486999 by metzlerd, er.pushpinderrana, jhodgdon: Create...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.