Problem/Motivation

Need to document form elements missed in the first pass including code examples for the following elements:

  • Datelist
  • Datetime
  • EntityAutocomplete
  • File
  • Item
  • ImageButton
  • LanguageConfiguration
  • LanguageSelect
  • ManagedFile
  • PathElement

Proposed resolution

For each of these elements: Create form element documentation for each class containing:

  • A description of what the element does.
  • Documentation for properties that are integral to using the element. This is not necessary if the element is for internal use during the rendering process.
  • A simple render array example illustrating its usage or an @see link to a concise example, except for internal-use elements

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.

Issue fork drupal-2599742

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

metzlerd created an issue. See original summary.

metzlerd’s picture

Title: Document Missing HTML Render Elements » Document Missing Form Elements
metzlerd’s picture

Issue summary: View changes
rakesh_verma’s picture

Can a newbie help in this issue?

metzlerd’s picture

Absolutely, provided you are a bit of a developer. You can use the existing documentation as a guide. What I have been doing is trying to use these elements in my own sandbox module, and then copying/pasting code examples into the comments. If that sounds like something you can do, by all means jump in. Let me know if there is anything that I can do to help you along.

metzlerd’s picture

Assigned: Unassigned » metzlerd

@rekesh_verma: You didn't assign so I'm assuming that you decided not to work on this. Let me know if I'm wrong about that.

rakesh_verma’s picture

@metzlerd: Definitely I want to work on this one. Sorry, I didn't know I have to assign this to myself. Can you tell me if you have already included any of them in your code? And please pardon me for not replying. I came back the same day to reply but I had some connectivity issues at that time so couldn't reply.
Regards,
Rakesh Verma

metzlerd’s picture

Version: 8.0.x-dev » 8.2.x-dev
Assigned: metzlerd » Unassigned
StatusFileSize
new19.52 KB

Yes, I'd started today, cause I had some time. I'm kind of out of time for a bit so feel free to take this and run with it. It needs refinement, editing and verification. This patch was rolled against 8.2.x. You should definitely start with that and we'll backport after we get it sorted out. If you are interested in sample code, I've been working on a contribution to the examples module which you can find at:

https://github.com/metzlerdl/d8_examples

If you enable this module you can see some examples at examples/fapi_example.

My habit is to make sure I understand each element there before I try and work on the documentation.

Again, let me know if I can be of any help.

rakesh_verma’s picture

Assigned: Unassigned » rakesh_verma

Thanks, I just completed my drupal ladder and my proposal for GSoC. I will start working on it by tonight.
Thanks a lot.

ajalan065’s picture

Status: Active » Needs review

Go Testbot

rakesh_verma’s picture

Status: Needs review » Needs work

Form elements miss documentation and code examples.

rakesh_verma’s picture

StatusFileSize
new797 bytes

@metzlerd: Added the example code for language test. Please review.

metzlerd’s picture

Some procedural feedback: When extending the effort of a patch, the best way forward is to apply the patch, make edits and then submit a patch that includes both sets of work, along with an interdiff that represents the difference between your patch and the one started.

Some specific feedback:

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

    Should include Properties section before here describing any language_select specific properties.

  2. +++ b/core/lib/Drupal/Core/Render/Element/LanguageSelect.php
    @@ -16,6 +16,16 @@
    + *     '#languages' => LanguageInterface::STATE_ALL,
    

    Is this property necessary? If so what does it do?

rakesh_verma’s picture

Great piece of advice. Thanks alot. Working on it :)

dagmar’s picture

Status: Needs work » Needs review
StatusFileSize
new20.69 KB
new6.13 KB

@jhodgdon warn me about this issue while I was working on #2710287: Image button properties are not documented.

I did some changes to consistently use array() instead of [] for arrays. Also we are not using two spaces for example codes.

Also removed #value for image buttons since they are not used on those type of elements.

The interdiff is against #8 with the patch #12 applied on top it.

jhodgdon’s picture

We should instead consistently use [] instead of array() for arrays. Thanks!

dagmar’s picture

Consistently using [] instead of array().

jhodgdon’s picture

Assigned: rakesh_verma » Unassigned
Status: Needs review » Needs work

Thanks for taking on this issue dagmar!! The latest patch is looking pretty good.

There are several things that still need to be fixed though:

  1. +++ b/core/lib/Drupal/Core/Datetime/Element/Datelist.php
    @@ -10,6 +10,48 @@
      * Provides a datelist element.
    

    What is a "datelist" element? We could use a better description of what it does, and how it differs from a Datetime.

    Also probably need an @see to the Datetime element.

  2. +++ b/core/lib/Drupal/Core/Datetime/Element/Datelist.php
    @@ -10,6 +10,48 @@
    + * Properties:
    + *   - #default_value: A DrupalDateTime object, adjusted to the proper local
    

    Formatting:

    The - for the list items should line up under the P in Properties. Everything is 2 spaces extra indented.

  3. +++ b/core/lib/Drupal/Core/Datetime/Element/Datelist.php
    @@ -10,6 +10,48 @@
    + *     user input strings back into a new date object on submission. No timezone
    + *     adjustment is performed.
    

    This last sentence about time zone adjustment is confusing to me, after having read the docs for the #date_timezone property below.

    I think one of them is incorrect and they seem to contradict each other?

  4. +++ b/core/lib/Drupal/Core/Datetime/Element/Datelist.php
    @@ -10,6 +10,48 @@
    + *   - #date_text_parts: Array of date parts that should be presented as
    

    Looking at where this came from... we've lost the information about which properties are required and which are optional.

    The optional ones should be written like this:

    - #data_part_order: (optional) Array of ...
    

    This comment also applies to other date/time elements!

  5. +++ b/core/lib/Drupal/Core/Datetime/Element/Datelist.php
    @@ -10,6 +10,48 @@
    + *   - #date_increment: The increment to use for minutes and seconds, i.e.
    + *     '15' would show only :00, :15, :30 and :45. Defaults to 1 to show every
    + *     minute.
    

    i.e. in this sentence is incorrect. This happens a lot in documentation (people confuse i.e. and e.g.). So, we prefer not to use i.e. or e.g. at all -- we had an issue on this recently that cleaned out a bunch of them.

    So, instead of "i.e." here, let's say "for example".

    Also the punctuation is incorrect. There should be a ; before "for example" and a , after it.

    These comments also apply to other date/time elements!

  6. +++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php
    @@ -10,6 +10,90 @@
      * Provides a datetime element.
    

    What is a "datetime" element? We could use a better description of what it does, and how it differs from a Datelist.

    Also probably need an @see to the Datelist element.

  7. +++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php
    @@ -10,6 +10,90 @@
    + * Examples of possible configurations include:
    + *   HTML5 date and time:
    + *     #date_date_element = 'date';
    + *     #date_time_element = 'time';
    + *   HTML5 datetime:
    + *     #date_date_element = 'datetime';
    + *     #date_time_element = 'none';
    + *   HTML5 time only:
    + *     #date_date_element = 'none';
    + *     #date_time_element = 'time'
    + *   Non-HTML5:
    + *     #date_date_element = 'text';
    + *     #date_time_element = 'text';
    

    This is not going to format well on api.drupal.org unless it is made into a bullet list (precede each line with - and the lists can be nested).

    Also I think it would be better to put these examples after the description of what the properties are. Right here it is a bit confusing. Or better yet, combine it with the Usage example section (maybe make 2 examples). Or ... do we even need this?

  8. +++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php
    @@ -10,6 +10,90 @@
    + * Properties:
    + *   - #default_value: A DrupalDateTime object, adjusted to the proper local
    

    Formatting: list elements - should line up under the P in Properties. Everything is indented 2 spaces too much.

  9. +++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php
    @@ -10,6 +10,90 @@
    + *     user input strings back into a new date object on submission. No timezone
    + *     adjustment is performed.
    

    See note about timezones from the Datelist element above.

  10. +++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php
    @@ -10,6 +10,90 @@
    + *   - #date_date_format: A date format string that describes the format that
    + *     should be displayed to the end user for the date. When using HTML5
    + *     elements the format MUST use the appropriate HTML5 format for that
    + *     element, no other format will work. See the format_date() function for a
    + *     list of the possible formats and HTML5 standards for the HTML5
    + *     requirements. Defaults to the right HTML5 format for the chosen element
    + *     if a HTML5 element is used, otherwise defaults to
    + *     entity_load('date_format', 'html_date')->getPattern().
    

    This section is very confusing.

    Also the format_date() function is deprecated, and it doesn't have the information that this documentation says to look at.

    And how do you use an HTML5 element? Very confusing.

  11. +++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php
    @@ -10,6 +10,90 @@
    + *   - #date_date_element: The date element. Options are:
    

    Ah, here's the element. Consider maybe moving this up, since the date format property references this? Would be way less confusing.

    Anyway, this may need some more explanation. What is it talking about? I think it should probably be saying "The HTML element used for the date portion" or something like that?

  12. +++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php
    @@ -10,6 +10,90 @@
    + *   - #date_date_callbacks: Array of optional callbacks for the date element.
    

    When are these callbacks called? What are their parameters and return values?

  13. +++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php
    @@ -10,6 +10,90 @@
    + *   - #date_time_element: The time element. Options are:
    

    See notes on the date_date_element above.

  14. +++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php
    @@ -10,6 +10,90 @@
    + *   - #date_time_format: A date format string that describes the format that
    

    See notes on date_date_format above.

  15. +++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php
    @@ -10,6 +10,90 @@
    + *   - #date_time_callbacks: An array of optional callbacks for the time
    

    See notes on date_date_callbacks above.

  16. +++ b/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php
    @@ -14,8 +14,24 @@
    + * The value returned by the element
    

    This looks like it was started but not completed?

  17. +++ b/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php
    @@ -14,8 +14,24 @@
    + * - #default_value:  An n entity object or an array of entity objects.
    

    stray "n"

  18. +++ b/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php
    @@ -14,8 +14,24 @@
    + * - #target_type: The entity type used in the autocomplete
    

    needs to end in .

  19. +++ b/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php
    @@ -14,8 +14,24 @@
    + * - #target_bundle: The bundle of the entity used in the control.
    

    what is a control?

  20. +++ b/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php
    @@ -14,8 +14,24 @@
    + * - #autocreate: Array defining defaults used by selections handlers for
    + *   entities that support automatic creation of entities such as taxonomy
    + *   terms.
    

    what is this trying to say? I don't understand it.

  21. +++ b/core/lib/Drupal/Core/Render/Element/Ajax.php
    @@ -21,11 +21,11 @@ public function getInfo() {
    -    return array(
    +    return [
           '#header' => TRUE,
    -      '#commands' => array(),
    +      '#commands' => [],
           '#error' => NULL,
    -    );
    +    ];
    

    This change is good to make, but not on this issue. This issue is only supposed to be about making documentation for a set list of element types. Can we make a new issue to cover the [] array syntax in other element types?

  22. +++ b/core/lib/Drupal/Core/Render/Element/Button.php
    @@ -20,10 +20,10 @@
    - * $form['actions']['preview'] = array(
    + * $form['actions']['preview'] = [
      *   '#type' => 'button',
      *   '#value' => $this->t('Preview'),
    - * );
    + * ];
    

    Same here... and for several others...

  23. +++ b/core/lib/Drupal/Core/Render/Element/Form.php
    @@ -5,6 +5,16 @@
    + * Usage example:
    + * @code
    + * $form = [
    + *   '#method' => 'post',
    + * ];
    + * @endcode
    

    This example is confusing. Most of the others have a #type => 'form' line, but this doesn't. It needs to be explained. Or the line needs to be added.

  24. +++ b/core/lib/Drupal/Core/Render/Element/ImageButton.php
    @@ -8,6 +8,17 @@
    + * - #src: Relative path to the image used in the button.
    

    Relative to what? And in the other issue, the usage example you had used "public://filename.png" -- is this also supported?

  25. +++ b/core/lib/Drupal/Core/Render/Element/Item.php
    @@ -9,6 +9,21 @@
    + * - #markup: The data to be display.
    

    display -> displayed

  26. +++ b/core/lib/Drupal/Core/Render/Element/Item.php
    @@ -9,6 +9,21 @@
    + * - #title: Title of the form element.
    

    Let's leave out the word "form" here.

  27. +++ b/core/lib/Drupal/Core/Render/Element/LanguageSelect.php
    @@ -11,6 +11,16 @@
      * language_element_info_alter() to provide a proper language selector.
      *
    + * Usage Example:
    

    This element seems to be missing Properties section.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

eojthebrave’s picture

Issue tags: -rc eligible
+++ b/core/lib/Drupal/Core/Render/Element/Date.php
@@ -13,11 +13,11 @@
- *   '#default_value' => array('year' => 2020, 'month' => 2, 'day' => 15,)
- * );
+ *   '#default_value' => ['year' => 2020, 'month' => 2, 'day' => 15]
+ * ];

This isn't actually valid. The Date element requires the default value to be a string in the format yyyy-mm-dd. And, FWIW this is also being addressed in this issue #2836530: Update Date element documentation for #date_date_format and usage for other date types such as time

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jhodgdon’s picture

Title: Document Missing Form Elements » Document several form elements that have no docs

This still needs to be done.

jhodgdon’s picture

Issue summary: View changes

Updating summary.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone made their first commit to this issue’s fork.

quietone’s picture

Status: Needs work » Needs review

Converted the MR. Then moved common date propertied to DateElementBase and moved the properties descriptions for methods in Dateitme and Datelist to the class documentation.

smustgrave’s picture

Shouldn't this be broken up some?

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

smustgrave’s picture

Status: Needs review » Needs work

Appears to need a rebase

sivaji_ganesh_jojodae made their first commit to this issue’s fork.

sivaji_ganesh_jojodae’s picture

I've rebased and added some least essential comments in the MR.