Introduce proper Form API #types for 'option' and 'optgroup', and make #options consistent.

Created on 3 December 2008, about 16 years ago
Updated 6 November 2023, about 1 year ago

Problem/Motivation

  • The rendering of select elements and their options is inconsistent with how checkboxes and radios are rendered
  • The markup of <option> and <optgroup> cannot be modified per-element

Proposed resolution

  • Introduce a proper #type optgroup and #type option
  • Use identical expansion of #options into sub-elements as is being used for #type checkboxes and radios except for the fact that it supports arrays as value which get expanded into optgroup elements
  • \Drupal\Core\Render\Element\Select::preRender() is duplicated by template_preprocess_select() and the former is not called by #type language_select elements

Remaining tasks

<!-- See https://drupal.org/core-mentoring/novice-tasks for tips on identifying novice tasks. Delete or add "Novice" from the Novice? column in the table below as appropriate. Uncomment tasks as the issue advances. Update the Complete? column to indicate when they are done, and maybe reference the comment number where they were done. -->

User interface changes

None.

API changes

  • \Drupal\Core\Form\OptGroup::flattenOptions() is moved to \Drupal\Core\Render\Element\Optgroup as it would be confusing to have two different OptGroup classes doing similar things; as part of the moving the separate protected method doFlattenOptions() is removed as it is unnecessary and can be replaced by a recursive call to flattenOptions()
  • form_flatten_options() is removed; this is not technically necessary, but was easy enough to do here
  • form_select_options() is removed
  • It is no longer supported to explicitly set #options to NULL as this is rather pointless
  • It is no longer supported to put objects which have a options member variable in #options as this is rather pointless
πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
FormΒ  β†’

Last updated about 4 hours ago

Created by

πŸ‡«πŸ‡·France lilou

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024