Problem/Motivation

Need to document render elements including code examples for the following elements:

  • HtmlTag
  • InlineTemplate
  • Label
  • Link
  • MoreLink
  • Pager
  • StatusMessages
  • SystemCompactLink

There may be other elements, but these seem straightforward candidates for documentation.

Proposed resolution

Document attributes and generate a code example.

Remaining tasks

Make a patch.

User interface changes

No. API docs only.

API changes

No. API docs only.

Data model changes

No. API docs only.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

metzlerd created an issue. See original summary.

metzlerd’s picture

Issue summary: View changes
metzlerd’s picture

Issue summary: View changes
jhodgdon’s picture

Issue summary: View changes

Adding:
SystemCompactLink

metzlerd’s picture

Assigned: Unassigned » metzlerd

I've started this... but it will take me a bit to find the time to finish.

metzlerd’s picture

Status: Active » Needs review
FileSize
6.27 KB
jhodgdon’s picture

Status: Needs review » Needs work

Looks pretty good!

A few suggestions:

  1. +++ b/core/lib/Drupal/Core/Render/Element/HtmlTag.php
    @@ -16,6 +16,23 @@
    + * - #attributes: (optional) An array of HTML attributes to apply to the
    + *   tag. The attributes are escaped, see \Drupal\Core\Template\Attribute.
    + * - #value: (optional) A string containing the textual contents of the tag.
    + * - #noscript: (optional) A boolean value. When set to TRUE, the markup
    + *   (including any prefix or suffix) will be wrapped in a <noscript> element.
    

    We could make this more concise with the types as something like this:

    - #attributes: (optional, array) HTML attributes to ...
    - #value: (optional, string) The textual content of the tag.
    ...

    Not sure if that is better? maybe.

  2. +++ b/core/lib/Drupal/Core/Render/Element/HtmlTag.php
    @@ -16,6 +16,23 @@
    + * - #noscript: (optional) A boolean value. When set to TRUE, the markup
    

    boolean -> Boolean

  3. +++ b/core/lib/Drupal/Core/Render/Element/InlineTemplate.php
    @@ -10,6 +10,22 @@
    + * - #template: The inline twig template used to render the element.
    

    twig -> Twig

  4. +++ b/core/lib/Drupal/Core/Render/Element/InlineTemplate.php
    @@ -10,6 +10,22 @@
    + * - #context: An array The variables available for use in the twig template.
    

    I think I would format this as:

    (array) The variables...

    Also twig -> Twig

  5. +++ b/core/lib/Drupal/Core/Render/Element/InlineTemplate.php
    @@ -10,6 +10,22 @@
    + *   Variable contents may be a render array.
    

    This is a bit ... unclear or garbled?

    Maybe say:

    Each variable may either be a string value or a render array.

    (if that is the correct meaning)

  6. +++ b/core/lib/Drupal/Core/Render/Element/InlineTemplate.php
    @@ -10,6 +10,22 @@
    + * Usage Exmaple:
    

    Example is misspelled. Also did we say "Usage Example" (title case) or "Usage example" (sentence case) in the previous patches?

  7. +++ b/core/lib/Drupal/Core/Render/Element/Label.php
    @@ -11,7 +11,8 @@
    + * of most form elements.  This element is used internally by the form system
    

    Remove extra space after . [By the way, I recognize this habit from learning typing back in 8th grade, AKA the Dark Ages. ;) ]

  8. +++ b/core/lib/Drupal/Core/Render/Element/Link.php
    @@ -15,6 +15,13 @@
    + * - #url: \Drupal|Url object containing information pointing to a routed or
    

    I guess that's a typo and it should be \Drupal\Url .. or isn't there another component to that namespace?

  9. +++ b/core/lib/Drupal/Core/Render/Element/Link.php
    @@ -15,6 +15,13 @@
    + * - #url: \Drupal|Url object containing information pointing to a routed or
    + *   non-routed path.
    

    It can probably also be an external link, which I think is not a path?

    SO maybe something like:

    An object containing URL information for an internal or external link.

    ?

  10. +++ b/core/lib/Drupal/Core/Render/Element/Link.php
    @@ -15,6 +15,13 @@
    + * - #options: (optional) An array of options to pass to the link generator.
    + *   see \Drupal\Core\Utility\LinkGeneratorInterface
    

    see => See and this last line should probably end in .

  11. +++ b/core/lib/Drupal/Core/Render/Element/Link.php
    @@ -15,6 +15,13 @@
    + *
    

    This one should have a usage example?

  12. +++ b/core/lib/Drupal/Core/Render/Element/MoreLink.php
    @@ -10,6 +10,14 @@
      *
    

    No docs of properties here? It seems at least a pointer to the base Link element would be useful, and if there is a default link text, we should mention that here?

  13. +++ b/core/lib/Drupal/Core/Render/Element/Pager.php
    @@ -12,6 +12,28 @@
    + * - #element: The pager ID, to distinguish bewteen multiple pagers on the same
    + *   page (defaults to 0).
    + * - #parameters: An associative array of query string parameters to append to
    + *   the pager.
    + * - #quantity: The number of pages in the list.
    + * - #tags: An array of labels for the controls in the pages.
    + * - #route_name: The name of the route to be used to build pager links. By
    + *   default no path is provided which will make links relative to the current
    + *   URL.  This makes the page more effectively cacheable.
    

    It seems like we should mention on all of these properties that you normally don't have to provide values for them, or what their default values are? This is only currently mentioned on #element and it's kind of implied by the usage example, but I think it would be good to state it.

    Also #quantity ... this could be confusing. Is it the max number of links to create or the number of pages that exist from the query?

    Also under #route_name, needs comma before "which"... and does providing this or not providing it make the page more cacheable?

  14. +++ b/core/lib/Drupal/Core/Render/Element/Pager.php
    @@ -12,6 +12,28 @@
    + * @code
    

    Missing the "Usage example" header.

  15. +++ b/core/lib/Drupal/Core/Render/Element/SystemCompactLink.php
    @@ -13,6 +13,16 @@
    + *   '#id' => FALSE,
    

    What is this being used for? Probably needs property documentation above.

metzlerd’s picture

Thanks for the review!

I removed the #id => false reference. It was copied from a core code snippet, but wasn't really used consistently throughout core, so I don't really understand when it's advisable or not. Other changes addressed (hopefully).

The tact I'm trying to take is to list (type, optional) for anything that doesn't have a default value. I guess we should try to decide whether we should clean this up in the editorial phase cause I don't think all the docs are consistent in this regard.

Let me know what you think.

metzlerd’s picture

jhodgdon’s picture

Status: Needs review » Needs work

Looking better!

By the way I'm out the next 3 weeks so no reviews for a while... you may be able to recruit Tim Plunkett or someone like that to review patches in the meantime.

A few minor questions/suggestions:

  1. +++ b/core/lib/Drupal/Core/Render/Element/HtmlTag.php
    @@ -16,6 +16,23 @@
    + * - #value: (string, optional) A string containing the textual contents of the tag.
    

    this line went over 80 chars. Wrap.

  2. +++ b/core/lib/Drupal/Core/Render/Element/HtmlTag.php
    @@ -16,6 +16,23 @@
    + * - #noscript: (Boolean, optional) When set to TRUE, the markup
    

    Probably in () we should use the types syntax we use for @param and @return, which would say:

    (bool, optional)

    See https://www.drupal.org/node/1354#types

    In regular text, "Boolean" is correct though.

  3. +++ b/core/lib/Drupal/Core/Render/Element/HtmlTag.php
    @@ -16,6 +16,23 @@
    + * Usage Example:
    

    The others now say "Usage example" not "Usage Example".

  4. +++ b/core/lib/Drupal/Core/Render/Element/InlineTemplate.php
    @@ -10,6 +10,22 @@
    + * - #context: (array) The variables available for use in the Twig template.
    

    I wonder if we should say "to substitute into" rather than "available for use" ... or something like that?

  5. +++ b/core/lib/Drupal/Core/Render/Element/InlineTemplate.php
    @@ -10,6 +10,22 @@
    + *   Each variable may be string or a render array.
    

    be string => be a string

    [did I do that? :) ]

  6. +++ b/core/lib/Drupal/Core/Render/Element/Link.php
    @@ -15,6 +15,21 @@
    + * - #title: The link text.
    

    Should we put #title into the usage example?

  7. +++ b/core/lib/Drupal/Core/Render/Element/Link.php
    @@ -15,6 +15,21 @@
    + * - #options: (optional) An array of options to pass to the link generator.
    + *   See \Drupal\Core\Utility\LinkGeneratorInterface.
    

    Hm. So we're passing in a URL object... are #options still relevant?

  8. +++ b/core/lib/Drupal/Core/Render/Element/MoreLink.php
    @@ -10,6 +10,19 @@
    + * - #title: The text of the link to generate (Defaults to 'More').
    

    Defaults => defaults

  9. +++ b/core/lib/Drupal/Core/Render/Element/Pager.php
    @@ -12,6 +12,29 @@
    + * - #quantity: The maximum number of numbered page links to create. (Defaults
    + *   to 9).
    

    In the 2nd line here, the . should be before the )

    Actually though, we normally don't put (Defaults to ...) in parens in other docs.

  10. +++ b/core/lib/Drupal/Core/Render/Element/Pager.php
    @@ -12,6 +12,29 @@
    + * - #route_name: The name of the route to be used to build pager links. By
    + *   defaults to '<none>', which will make links relative to the current
    

    I think "By" should be removed?

  11. +++ b/core/lib/Drupal/Core/Render/Element/Pager.php
    @@ -12,6 +12,29 @@
    + *   URL.  This makes the page more effectively cacheable.
    

    Extra space after the . in this line.

    And again, I'm confused about whether using the default or providing a different route makes the page more cacheable.

  12. +++ b/core/lib/Drupal/Core/Render/Element/SystemCompactLink.php
    @@ -13,6 +13,15 @@
    + * Descriptions are only hidden in system administration pages.
    

    What does this mean?

snehi’s picture

Assigned: metzlerd » snehi
snehi’s picture

Status: Needs work » Needs review
FileSize
9.12 KB
4.3 KB

Done as suggested.

rakesh.gectcr’s picture

@snehi,

Please try to work on the unassigned issue. There are lots of un assigned issues are available in the queue. It is assigned to some one , that means he is working on it, Please understand. You are doing this for many times. I found out in couple of issues.

Disadvantage: Somebody is assigned , they will be really following up that issues. Time is precious, should not end in wasting time of any contributors. Please do understand.

heykarthikwithu’s picture

Status: Needs review » Needs work

@snehi, push the patch changes of
/core/modules/user/src/PrivateTempStoreFactory.php
/core/modules/user/src/SharedTempStoreFactory.php
/core/modules/user/src/Theme/AdminNegotiator.php
to another issue, since they are part of user module (core/modules/user/src) and else other are part of /core/lib/Drupal/Core.

Having different patches for different modules will be more readability while pushing changes.

snehi’s picture

Assigned: snehi » Unassigned
metzlerd’s picture

Assigned: Unassigned » metzlerd
Status: Needs work » Needs review
FileSize
3.36 KB
6.59 KB

Regarding review in comment #10:

8. The #options are still merged into the link that gets rendered. Look at the comments to the preRenderLink and let me know what to do. I took them out, but am a bit nervous about whether it's the right approach.

10. I refactored the description. I don't really think this element is useful unless you're adding pages under admin. I know what functionality it's tied to but experimentation showed that it doesn't work as a stand-alone element for use on other pages. It may still be useful within the context of administration added by other modules, but I'm not really sure. If anyone knows more, I'd love clarification.

I removed the user module patches introduced by #12, and changed the approach to link title but otherwise used that patch, so thank you @snehi

jhodgdon’s picture

Status: Needs review » Needs work
Issue tags: -rc eligible

Thanks for the patches! Sorry for the delay in reviewing -- I've been on vacation and no one else, unfortunately, ever reviews docs patches. :(

Anyway, this is looking really good! A few very minor fixes could be done:

  1. +++ b/core/lib/Drupal/Core/Render/Element/Pager.php
    @@ -12,6 +12,29 @@
    + * - #element: (int) The pager ID, to distinguish bewteen multiple pagers on
    

    typo: between

    Also this should probably say (optional, int)

  2. +++ b/core/lib/Drupal/Core/Render/Element/Pager.php
    @@ -12,6 +12,29 @@
    + * - #route_name: The name of the route to be used to build pager links.
    

    This should also be marked (optional) right?

  3. +++ b/core/lib/Drupal/Core/Render/Element/SystemCompactLink.php
    @@ -11,7 +11,14 @@
    + * Provides link to show or hide help text on administration pages.
    

    link => a link

rakesh.gectcr’s picture

Assigned: metzlerd » rakesh.gectcr
rakesh.gectcr’s picture

Assigned: rakesh.gectcr » Unassigned
Status: Needs work » Needs review
FileSize
6.62 KB
1.53 KB

@jhodgdon,

I have updated the patch according to your comments.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks for the new patch! Almost there...

  1. +++ b/core/lib/Drupal/Core/Render/Element/Pager.php
    @@ -12,6 +12,29 @@
    + * - #element: (optional, int) The pager ID, to distinguish between multiple pagers on
    

    Good. But this line is now over 80 characters, so it needs to be rewrapped.

  2. +++ b/core/lib/Drupal/Core/Render/Element/Pager.php
    @@ -12,6 +12,29 @@
    + * - #route_name: (optional) The name of the route to be used to build pager links.
    

    Here too.

rakesh.gectcr’s picture

Assigned: Unassigned » rakesh.gectcr
rakesh.gectcr’s picture

Status: Needs work » Needs review
FileSize
6.61 KB
1.19 KB

@jhodgdon,

Sorry , i could have been noticed that at the first place before uploading previous patch.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks!

+++ b/core/lib/Drupal/Core/Render/Element/Pager.php
@@ -12,6 +12,29 @@
+ * - #route_name: (optional) The name of the route to be used to build pager
+ *   links defaults to '<none>', which will make links relative to the current

Oops. This was two sentences in the last patch -- needs . after links and the Defaults should be capitalized to start a new sentence.

rakesh.gectcr’s picture

Status: Needs work » Needs review
FileSize
6.62 KB
1.19 KB

@jhodgdon sorry again , I --previous patch and went back to #19.

changes done. :)

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! This all looks right to me now.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 2cc3c86 and pushed to 8.0.x and 8.1.x. Thanks!

  • alexpott committed 0eceb0c on 8.1.x
    Issue #2599454 by rakesh.gectcr, metzlerd, snehi, jhodgdon: Document...

Status: Fixed » Closed (fixed)

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

darkdim’s picture

Hi guys,
How to add a class to tag in an element "more_link"?
What to do to use the hook?

jhodgdon’s picture

@darkdim -- this issue is closed. Please file a new issue... except if you are looking for programming support, the Drupal Core issue queue is not a great place to find it. Although you can create issues in Drupal Core and mark the category as "support request", we don't really handle support requests in the Drupal Core issue queue as a regular practice (that option is mostly there for filing support issues for contributed modules and themes).

There are several support options listed if you click on "Support" at the top of Drupal.org, which will take you to:
http://drupal.org/support

There you can find out about the Drupal IRC and Slack channels, and the Forums, which are our two main support mechanisms in the Drupal community. You might also try http://drupal.stackexchange.com/

Good luck with your issue!

darkdim’s picture

@jhodgdon Thank you! Sorry