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.
Comment | File | Size | Author |
---|---|---|---|
#4 | 2175281-dont-hardcode-form_builder-element_type-4.patch | 837 bytes | torotil |
Comments
Comment #1
torotil CreditAttribution: torotil commentedComment #2
torotil CreditAttribution: torotil commentedComment #3
torotil CreditAttribution: torotil commentedHere 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 …
Comment #4
torotil CreditAttribution: torotil commentedI'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.
Comment #7
quicksketchWorks 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.