Form elements

Last updated on
20 April 2021

Suggestions based on name, type and form id

Formdazzle adds suggestions to elements and parts based on the corresponding

  • form element name
  • form element type (checkbox, actions, more_link, etc.)
  • form id

It orders all of these from least-specific to most-specific: [element_type]__[form_id]__[element_name]. For example, here's the suggestions for the "Site slogan" text input on the Site information form:

<!-- FILE NAME SUGGESTIONS:
   * input--textfield--system-site-information-settings--site-slogan.html.twig
   * input--textfield--system-site-information-settings.html.twig
   * input--textfield.html.twig
   x input.html.twig
-->

Form element labels

A form element’s label can’t be altered with form_alter because it isn't created until hook_preprocess_form_element(). Formdazzle waits until the label is created and then adds a useful theme suggestions of form_element_label__[form_id]__[form_element_name].

Without Formdazzle:

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'form_element_label' -->
<!-- BEGIN OUTPUT from 'core/themes/seven/templates/classy/form/form-element-label.html.twig' -->

With Formdazzle:

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'form_element_label__system_site_information_settings__site_name' -->
<!-- FILE NAME SUGGESTIONS:
   * form-element-label--system-site-information-settings--site-name.html.twig
   * form-element-label--system-site-information-settings.html.twig
   x form-element-label.html.twig
-->
<!-- BEGIN OUTPUT from 'core/themes/seven/templates/classy/form/form-element-label.html.twig' -->

Theme wrapper suggestions

In addition to the suggestions that it adds to a form element's #theme properties, Formdazzle also adds suggestions to #theme_wrappers properties. (The code Formdazzle uses to do this is actually quite complicated, but themers have better things to do then understand the internals of Drupal\Core\Theme\ThemeManager::render().)

Help improve this page

Page status: No known problems

You can: