function form_select_options

Same name and namespace in other branches
  1. 11.x core/includes/form.inc \form_select_options()
  2. 10 core/includes/form.inc \form_select_options()
  3. 9 core/includes/form.inc \form_select_options()
  4. 8.9.x core/includes/form.inc \form_select_options()
  5. 7.x includes/form.inc \form_select_options()

Converts the options in a select element into a structured array for output.

This function calls itself recursively to obtain the values for each optgroup within the list of options and when the function encounters an object with an 'options' property inside $element['#options'].

Parameters

array $element: An associative array containing properties of the select element. See \Drupal\Core\Render\Element\Select for details, but note that the #empty_option and #empty_value properties are processed, and the #value property is set, before reaching this function.

array|null $choices: (optional) Either an associative array of options in the same format as $element['#options'] above, or NULL. This parameter is only used internally and is not intended to be passed in to the initial function call.

Return value

mixed[] A structured, possibly nested, array of options and optgroups for use in a select form element.

  • label: A translated string whose value is the text of a single HTML option element, or the label attribute for an optgroup.
  • options: Optional, array of options for an optgroup.
  • selected: A boolean that indicates whether the option is selected when rendered.
  • type: A string that defines the element type. The value can be 'option' or 'optgroup'.
  • value: A string that contains the value attribute for the option.

Deprecated

in drupal:11.6.0 and is removed from drupal:13.0.0. Use \Drupal\Core\Form\FormSelectOptions::process() instead.

See also

https://www.drupal.org/node/3412600

\Drupal\Core\Form\FormSelectOptions::process()

File

core/includes/form.inc, line 49

Code

function form_select_options($element, $choices = NULL) : array {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.6.0 and is removed from drupal:13.0.0. Use \\Drupal\\Core\\Form\\FormSelectOptions::process() instead. See https://www.drupal.org/node/3412600', E_USER_DEPRECATED);
  return FormSelectOptions::process($element, $choices);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.