It seems that for unique fields the form-API #type of the default field is forced on the #form_builder type. This basically forces us to create new form-elements (hook_element_info()) for each new form_builder field.

function form_builder_get_form_type($form_type = NULL, $reset = FALSE) {
  // …
        // Update the default elements with some defaults.
        // Note that if a field is not removable, it doesn't have a default.
        if ($field['addable']) {
          if ($field['unique']) {
            $field['default']['#form_builder']['element_id'] = $field_key;
            $field['default']['#form_builder']['element_type'] = $field_key; // this is where the hardcoding happens.
          }
          elseif (!isset($field['default']['#form_builder']['element_type'])) {
            $field['default']['#form_builder']['element_type'] = $field_key;
          }
        }
  // …
}

Also it seems to be quite counter intuitive that hook_form_builder_types() returns a list of fields instead of a list of types. With the naming of the hook one would expect to return a list of form_builder_types.

The fact that the form_builder_type is determined implicitly by $types[$form_type][$field_name]['default']['#form_builder']['element_type'] further complicates things.

It seems that during the development of form_builder the concept of a form_builder_type was mixed up with fields at some point.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

torotil’s picture

Title: Don't force $form['#type'] == form_builder['type'] for unique fields. » Don't force $form['#type'] == form_builder['element_type'] for unique fields.
torotil’s picture

Issue summary: View changes
torotil’s picture

Status: Active » Needs review
FileSize
869 bytes

Here is a rather harmless patch that makes it possible to override the form_builder element_type. It's still the question whether the field vs. element_type mixup should be changed too …

torotil’s picture

Title: Don't force $form['#type'] == form_builder['element_type'] for unique fields. » Don't force $form['#type'] == $field_key for unique fields.
Issue summary: View changes
FileSize
837 bytes

I've just noticed that this patch was based on a previous (now obsolete) patch. Here is one that applies to the unmodified 7.x-1.4 release.

  • Commit c06dcc1 on 7.x-1.x by quicksketch:
    Issue #2175281 by torotil: Don't force ['#type'] ==  for unique fields.
    

  • Commit 69776dd on 6.x-1.x by quicksketch:
    Issue #2175281 by torotil: Don't force ['#type'] ==  for unique fields.
    
quicksketch’s picture

Status: Needs review » Fixed

Works for me, thanks! Yeah hook_form_builder_types() might not be the best-named hook, but at this point in the development I don't think it'd be wise to change it.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.