Question

Form API Reference gives information about which properties to use for a form array, for Drupal 7.

Where can I see what properties I can use in buildForm(array $form, FormStateInterface $form_state), such as #type, #title, #required? How can I know the other possible properties?

Actually I'm using the Drupal 7 information in Drupal 8, and it works, but there should/must be an updated page, I guess.

Was it helpful?

Solution

Many of the form element properties are listed in the documentation for the FormElement class. The properties described there are:

  • #after_build
  • #ajax
  • #array_parents
  • #default_value
  • #description
  • #disabled
  • #element_validate
  • #field_prefix
  • #field_suffix
  • #input
  • #parents
  • #process
  • #processed
  • #required
  • #states
  • #title
  • #title_display
  • #tree
  • #value_callback

Then, as Form and render elements says:

Each form and render element type corresponds to an element plugin class; each of them either extends \Drupal\Core\Render\Element\RenderElement (render elements) or \Drupal\Core\Render\Element\FormElement (form elements). Usage and properties are documented on the individual classes, and the two base classes list common properties shared by all render elements and the form element subset, respectively.

(Emphasis is mine.)

There isn't a single page describing all the form element properties, but there is a page for each plugin class that implements a form element.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top