0

Every webform element has a little section like this:

Form display section with Title display, Description display, and Help display all set to " - Default -"

Where can one set these defaults, for Title display location, Description display location, and Help display location?

It does not appear to be in any of the webform overall settings or webform specific settings.

If it's the default for the element type, is there a programmatic way to override the default (but not if set for an individual element)?

Doesn't matter much whether setting or overriding this default on a sitewide or webform-specific level, just want the ability to switch Title display from "Inline" to "Before" for all the elements on a form, as design requests change, without having to edit all individually.

2
  • 1
    Export the config, edit all the webform.FORMNAME.yml files in your config/sync directory, re-import the config. Your favourite IDE will happily search-and-replace them all in one shot. (Before exporting, change one field to get the old and the new config values to be switchted.)
    – Hudri
    Jun 14, 2021 at 12:34
  • Found the "Default description display" setting at /admin/structure/webform/config/elements which makes me think the lack of Default title display setting is an oversight— on my part or webform's!
    – mlncn
    Jun 14, 2021 at 12:38

2 Answers 2

1

It looks default title display is set in Drupal core:

https://git.drupalcode.org/project/drupal/-/blob/9.5.x/core/lib/Drupal/Core/Form/FormBuilder.php#L923-930

1

Per Webform maintainer Jacob Rockowitz:

In your theme or module you can create a hook_preprocess_form_element() which overrides the default #title_display set via template_preprocess_form_element().

@see template_preprocess_form_element().

Or:

Maybe you can use hook_webform_element_alter() to set the #title_display before template_preprocess_form_element() sets it.

I specifically avoided implementing a customizable default #title_display and #description_display because some themes have different default #title_display.

From How to set the default Title position for an element? (Issue #3003067 on Drupal.org)

So as ognockocaten suggests, 'default' means 'the default of Drupal' (or the theme if it alters this), not a default set in Webform.

Also, in my experience, Webform has minimal CSS to get this to work and is likely to fail depending on your theme's CSS, you may need to add styles in your theme for the classes webform-element--title-inline > .label and webform-element--title-inline > .control to ensure that the Inline option does indeed put the label and the input inline, for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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