Removing a default field from the default palette of form_builder

Matthias Weiss's picture
Matthias Weiss

There are form_builder form elements that have the unique attribute. That means that these elements should only occure once in a webform, there shouldn' be a 2nd field of this type in your webform.

form_builder handles these fields so that when you drag & drop them into your form, they get removed from your palette of field elements.

In the code snippet below I'm using this behavior to hide an element from the default palette.

In the module you're writing, use the hook_form_builder_types_alter hook to hide the element(s) like this:

* Implements hook_form_builder_types_alter().
* remove elements from the default palette
function my_module_form_builder_types_alter(&$types) {
  if (isset($types['webform']['email']) == TRUE ) {
    $types['webform']['email']['unique'] = TRUE;
    $types['webform']['email']['in_use'] = TRUE;

Yes, this is an ugly hack, but it works.


Add new comment