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.

  • 2
  • @Kevin, I don't see the where in that page says the field can have entries like "#title", "#type" or "#required" etc. Where can I have this information? I've edited the question to be more clear. – dxvargas Jan 9 '19 at 15:28
  • 2
    It's really hard to find this information because it's not presented in the same manner. Essentially all elements implement ElementInterface::getInfo(), and this is where that information is for each element. The api project on drupal.org really should implement a way to aggregate things like this. – mradcliffe Jan 9 '19 at 22:14

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.