Problem/Motivation

New documentation standards for form elements are being discussed at #1617948: [policy for now] New standard for documenting form/render elements and properties. Whereas there is still some debate as to how to document common elements. There has been consensus that code examples and properties specific to the form should be documented with the classes that implement them. This issue serves as a meta-issue to track the work required to move code examples and property documentation into those classes.

Proposed resolution

Create child issues for each of the "similar" elements (e.g. those that use #options). 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.
  • A simple render array example illustrating its usage or an @see link to a concise example.

Remaining tasks

To be done last #2603810: [meta] See what else needs updating in Form/Render element docs

Comments

jhodgdon’s picture

It looks like all the existing child issues have been completed, but I think that there are probably more groups of form/render elements that need documentation still?

jhodgdon’s picture

I took a look at the classes in
core/lib/Drupal/Core/Render/Element/
to see which ones still need improved docs. I think this is the list... maybe not all of them need docs (this was a quick scan) but they bear another look at least:

Ajax
File
Form
Html
HtmlTag
ImageButton
InlineTemplate
Item
Label
LanguageSelect
Link
MoreLink
Operations
Page
PageTitle
Pager
PathElement
StatusMessages
SubmitCompactLink
Token

metzlerd’s picture

Thanks I created an issue for the obvious Render elements. I'll try and get to another issue for the remaining form elements. Here's some notes on the remaining items;

Ajax - Looks like it only gets used as part of another element? Need to research this.
File - Form element
Form - Not sure this can be used directly?
Html - Not sure this can be used directly - used to theme the page?
ImageButton - Form Element
Item - Form Element
LanguageSelect - Form Element
Operations - Use is the same as drop button - do we duplicate docs?
Page - Not sure this can be used directly
PageTitle - Not sure we can use this directly
PathElement - Form Element
SubmitCompactLink - Couldn't find this
Token - I think we agreed this should not have code examples.

Given the number of elements that might not be usable in a page controller, perhaps we should come up with some kind of "Internal Use Only" language that gets included in these to inform contrib developers?

jhodgdon’s picture

Form - yeah, well. So this is only set in FormBuilder::prepareForm(). However, it is pretty common for individual form-generating methods (implementations of FormInterface::buildForm() ) to set various properties of the outer form array. So I would think we should document those properties (the old FAPI reference should list them).

Operations, Token - agreed, sorry for including those. Too quick of a look. :(

SubmitCompactLink - oops. I meant SystemCompactLink. Adding this to your new Render issue.

Html/Page/PageTitle - agreed those are used internally by Drupal to render the page. Let's just mention that in their docs. Added issue for that, and ... well I will put Form on there too.
#2599784: Document Form, Html, Page, and PageTitle Elements

Also I should mention, if you didn't see it in the sidebar, that I created an issue for documenting the standard shared form/render properties: #2599442: Document common form/render element properties

Great! So now we have issues for all the remaining ones in the main directory there... may need to document a few more living in core modules, and I'll check on that shortly.

jhodgdon’s picture

Oh. I was also going to tell you that I showed off some of the output of your recent patches at BADCamp and everyone seemed very happy with (a) the results and (b) the maintainability of having the docs there. So THANKS metzlerd!

And see also #2596821: Make an "Elements" listing page, which will make a page listing all of those elements, once it is deployed to api.drupal.org; also I did #839550: Ability to add documentation headers to global listing pages (Classes, Functions, etc.), which will let us put a documentation header on that page. Woot! Yeah BADCamp!

tr’s picture

So what about \Drupal\Core\Render\Element\Date ?

Personally I think this issue should be Critical, because I see it as unacceptable to release 8.0 without a complete list of form elements along with documentation for each.

mile23’s picture

The release cycle is pretty much set in stone at the moment, though code style and documentation changes can happen. Upping the priority would be counter productive at this point.

There's an accompanying form_example being put together mainly by @Metzlerd, over in the Examples project, which has a little more latitude with the documentation and code samples: #2102659: Add new Form API example module for Drupal 8

metzlerd’s picture

@TAS: Date documentation has been committed. We're still working on the pieces, but this is getting tantilizingly close to completion.

See:

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...

jhodgdon’s picture

I'm going to see if I can get the API module changes that make a list of these elements up on api.drupal.org in the next few days too.

tr’s picture

@Mile23: Yes, I'm sure it will expedite the release of 8.0 if long-standing issues are swept under the rug.

Right now form elements aren't documented, and that has been a problem for years. Previous issues were recently closed as duplicates in favor of this current issue. Some previous issues have been MAJOR, so this is a downgrade of the importance. In addition, closing those issues has hidden all the previous input and concerns that have been raised.

As a developer, I currently have no idea what form elements are allowed and what their required/optional parameters are.

@metzlerd: Apparently Date was meant to be internal and doesn't work as a stand-alone element. See the details at https://www.drupal.org/node/2528482#comment-10145050 . While using #type = 'date' doesn't cause a PHP notice anymore, it still doesn't work as expected.

Documentation is important not only for contrib developers, but also for core developers - if there is no documentation then there is nothing to test to make sure it works as designed.

metzlerd’s picture

I hear your frustration, but I think the best way forward is to continue the work we are doing. I am continuing to work this issue with the time that I have available as a volunteer because I believe like you do that the documentation of form and render elements is an important effort. I'm not sure I share the optimism that you have that changing the priority will bring more resources. I have been working this issue since May slowly but surely, and will continue to do so until its' done. No core committer has stood in the way of this work yet, so I'm optimistic that we're close.

The only reason to close those issues that I know if is that this is where we are actually working towards a solution. I'm not sure what concerns you have that aren't being addressed, but feel free to raise them on the appropriate issue, or point me to something that can be acted on. I'm most interested in moving this issue forward, so we'll have the documentation we both want as fast as I can make it happen.

Thanks for pointing me to the issue about the date element. I'll look at that to see if I can find some appropriate guidance. From my perspective we'll probably continue to document the element on the assumption that it is expected to be used. Just because it's not used in core doesn't mean that it is for internal use only.... but I'll let others weigh in on that. We'll try and at least document deviations from expected behavior. That's all I can really do.

jhodgdon’s picture

@TR: I am a bit bewildered by your statement that "Form elements are not documented", which seems to be mostly based on problems you have identified in the Date element documentation. If there's an issue about the Date element documentation, by all means please file an issue and let's get it fixed. You seem to know more about it than those of us who patched, reviewed, and committed the issues where the Date element class and the other classes were documented, which is too bad. But the nice thing about documentation is that it is not set in stone -- if we make an issue and a patch, we can still fix it. A devoted issue saying what we need to do to fix that Date documentation would be very helpful, so that we can make it correct -- could you please file one and mark it as having this one as a parent so it doesn't get lost? Thanks!

As far as having a list of all elements, yes we definitely need one, and I've been working on it. It should be on api.drupal.org ... later today or tomorrow.

I also think that the more common elements, like Checkboxes etc., are pretty well documented now, and we also have documentation for the standard form/element properties on
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!Element!Re...
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!Element!Fo...
as of a few days ago.

And there are also two topics that cover form and render arrays:
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!theme.api....
https://api.drupal.org/api/drupal/core!core.api.php/group/form_api/8

So... If after reading all of that, you find that there are things that haven't been documented, please rather than just complaining that "it's not documented", file specific issues and we'll get it documented. Documentation issues don't block release, and can be fixed after release. So let's at least make sure the issues get filed for problems or lacks that exist, and we'll eventually get them done. Thanks!

jhodgdon’s picture

So... the list of form/render elements is now being built on api.drupal.org -- it should be complete in an hour or two at:
https://api.drupal.org/api/drupal/elements/8
Hm. I think it's mostly there now.

On #2603818: Add defgroups for listing page headers for api.drupal.org I have a patch that will add a documentation header to that page (as well as the Classes, Namespaces, and Services listing pages). A review of that patch would be greatly appreciated, and would further the cause of having documentation available. Thanks!

vorapoap’s picture

Can someone make a redirect from this page

https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.h...

to

https://api.drupal.org/api/drupal/elements/8

A lot of people coming from Google..
And I personally find the old format easier to navigate than the new one.

jhodgdon’s picture

Sorry that you prefer the old format, but it was a very outdated document because it was nearly impossible to maintain.

I'll file an issue to get the redirect done, which we meant to do and forgot -- sorry about that.
#2671300: Add redirect for D8 form api reference

metzlerd’s picture

I was at the Render API documentation page and didn't see any way to navigate to the new list of elements (always trying to use the documentation that we write.... ). It would seem we should have something in those Docs that connects these up. The closest thing we get on https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21... is saying:

See the Plugin API topic for general information on plugins, and look for classes with the RenderElement or FormElement annotation to discover what render elements are available.

I would think adding some kind of link that says something like, "See Render Elements for a list of render elements provided by core." would be the best approach but am interested in other thoughts.

jhodgdon’s picture

Yes, we should link that to https://api.drupal.org/api/drupal/elements

I thought we had already done so but apparently not.

metzlerd’s picture

Ok. Child issue has been added. My laptop is on the fritz, but I'll try and get to this when it's back in working order if no one else has.

Dave

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.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.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should 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.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should 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.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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

We need to get back to this. Someone just created an issue and I added it as a child of this one:
#3157135: Properties of Form FormElement are missing

This issue is still open too:
#2599742: Document several form elements that have no docs

So I think we need to go through all of the elements on
https://api.drupal.org/api/drupal/elements/9.0.x
and see which ones still need documentation, make issues for them, and fix them.

jhodgdon’s picture

Today I went through all of the elements on
https://api.drupal.org/api/drupal/elements/9.0.x
I clicked through to each class, and looked to see if the class had documentation on Properties and a Usage Example. I did not verify that the property documentation was correct or complete. I skipped a couple whose documentation said they were for internal use during rendering, like Label and Radio.

The following classes are missing Properties and Usage Example, and should probably have them added (there may be a few that don't have special properties and don't need additional docs, but I think most of these do):
core/lib/Drupal/Core/Render/Element/Ajax.php
core/modules/contextual/src/Element/ContextualLinks.php
core/modules/contextual/src/Element/ContextualLinksPlaceholder.php
core/lib/Drupal/Core/Datetime/Element/Datelist.php
core/lib/Drupal/Core/Datetime/Element/Datetime.php
core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php
core/modules/field_ui/src/Element/FieldUiTable.php
core/lib/Drupal/Core/Render/Element/Fieldgroup.php
core/lib/Drupal/Core/Render/Element/Fieldset.php
core/lib/Drupal/Core/Render/Element/Form.php
core/lib/Drupal/Core/Render/Element/Html.php
core/lib/Drupal/Core/Render/Element/ImageButton.php
core/lib/Drupal/Core/Render/Element/Item.php
core/modules/language/src/Element/LanguageConfiguration.php
core/lib/Drupal/Core/Render/Element/LanguageSelect.php
core/modules/file/src/Element/ManagedFile.php
core/lib/Drupal/Core/Render/Element/Page.php
core/lib/Drupal/Core/Render/Element/PageTitle.php
core/lib/Drupal/Core/Render/Element/PathElement.php
core/modules/filter/src/Element/ProcessedText.php
core/modules/responsive_image/src/Element/ResponsiveImage.php
core/lib/Drupal/Core/Render/Element/Search.php
core/lib/Drupal/Core/Render/Element/StatusReport.php
core/modules/system/src/Element/StatusReportPage.php
core/lib/Drupal/Core/Render/Element/Token.php
core/modules/toolbar/src/Element/Toolbar.php
core/modules/toolbar/src/Element/ToolbarItem.php
core/modules/views/src/Element/View.php

jhodgdon’s picture

osab’s picture

StatusFileSize
new49.22 KB

Hi! I've checked all properties of Elements from web/core/lib/Drupal/Core/Render/Element folder to found which of them are missed in documentation. Maybe, some properties description was already added in issues, nevertheless, I hope attached report is correct and will be useful.

jhodgdon’s picture

Thanks for doing that!

I'm a bit confused though. I started with Button. Your document lists these properties as not being documented:

‘#limit_validation_errors’
'#value'
'#name'
'#executes_submit_callback'
'#submit' 
'#widget_id' 

But when I go to the Button class:
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...
that page documents both limit_validation_errors and value... so those should not be in your list.

widget_id... Where did that come from? It doesn't seem like that is a property of Button? I can't see that it uses the submit property either?

I didn't get past Button because I didn't understand the results there.

Also to think about: some of the properties you listed might be for internal use only during the rendering process. We really only want to doucment the properties that someone who is using the form/render element in a render array would need to know about.

osab’s picture

StatusFileSize
new48.14 KB

Thanks @jhodgdon.
You are right, of course. Seems for Button are missed only 3 properties:

Button extends FormElement

'#name'
'#executes_submit_callback'
'#submit' 
Also to think about: some of the properties you listed might be for internal use only during the rendering process. We really only want to doucment the properties that someone who is using the form/render element in a render array would need to know about.

- Ok, it really make sense. Not sure, that I can confidently differentiate which of these properties are for internal use only.
So, I just searched in core this elements properties and made a list all that are not mentioned in web/core/lib/Drupal/Core/Render/Element/RenderElement.php, web/core/lib/Drupal/Core/Render/Element/FormElement.php,
or directly in the appropriate element class. I apologise in advance for the inaccuracies, I will correct if possible, and I've attached updated list.

osab’s picture

@jhodgdon, maybe it will be more helpful to have editable list, so I've attached txt. If you wish, you can help to remove internal properties from it.

jhodgdon’s picture

OK, this is better...

So it seems to me that we should document the following properties on the FormElement class:
#validate
#submit
#executes_submit_callback

#name
#value

#error_no_message

We should probably go through the FormBuilder, FormElement, and FormValidator classes, and inline_Form_errors.module, and see if there are any other common properties for forms that are implicit in building, validating, and error handling that we've missed.

Also... I'm wondering where your list came from? Because there are still properties that you've listed that I have no idea why you think they are properties of those particular elements? For instance, anything with "test" on it is probably suspect, such as #form-test_required_error. Just because someone has used a particular element in a test with a particular property doesn't mean it is actually a property that the element supports. We only want to document the supported properties. Tests often do weird things.

osab’s picture

Ok, all with "test" in this list should be ignored, thank you for explanation!

jhodgdon’s picture

But the question still remains, where did the other items come from that you think should be documented?

osab’s picture

@jhodgdon I looked throw core/ folder predominantly, but maybe some properties were in contrib modules and as you said they can be used only in that particular cases. I've removed all extra modules from my clean D8 installation already. So, let me re-check.

And some examples:
InlineTemplate - '#cell_attributes' used here web/core/modules/field_ui/src/Form/EntityDisplayFormBase.php, buildFieldRow()
Number - '#maxlength' in web/core/modules/editor/editor.admin.inc, editor_image_upload_settings_form()
Radio - '#return_value' in web/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php, processContainerRadios()

Maybe this is also some specific cases? I just wanted to have list of all available properties as we have in D7

jhodgdon’s picture

Yeah, sometimes particular uses of templates would add properties that are specific to their use, especially if they override a theme template. So I think we should only document properties that we can verify are actually handled by the Element class, its default theme template and preprocessing, the FormBuilder and FormValidator classes, and the RenderElement and FormElement base classes.

That is how we decided which properties to document the first time around. Unfortunately:
- Not all elements got documented (there are still open issues)
- Since we did that, additional properties were added and as usual, no one bothered to update documentation.

So... I think what you've done is a useful first step, but we will still have to verify that the properties are part of the base functionality, and also if they are, decide where to document them (which could be on the specific element class or the RenderElement or FormElement base class). Probably for now it is not worth the time to pare down your list to just Core -- probably you don't have too many extras... but you might also not have all of the properties that are supported (it's possible they are never used in a Form or Render array in Core).

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

gersonjl’s picture

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

Hello, me and some colleagues are working on improving/creating documentation both on wiki and API on this meta issue.

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.

liam morland’s picture

For me, the most important missing documentation is that we need a Drupal 10/11 version of the Drupal 7 "Form API Reference" page. Perhaps this is done as more than one page, but somewhere there needs to be list of valid values for #type and a way to find out what properties can be used with each type.

quietone’s picture

Issue summary: View changes

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.