You are here

function hook_form_builder_element_types in Form Builder 7

Same name and namespace in other branches
  1. 7.2 form_builder.api.php \hook_form_builder_element_types()

Define the elements and properties supported by a form.

All modules that wish to create an configurable form need implement this hook. It defines to Form Builder what types of elements the implementing module knows how to modify. Within each element that is modifiable, the properties that may be changed are also listed.

Parameters

string $form_type: The form type of the form as declared in hook_form_builder_form_types().

mixed $form_id: The ID of the form.

Return value

An array of available elements types for this form. Each field contains the following properties:

  • class: The class used to handle this element type. Defaults to the 'element class' attribute of the form type.
  • title: The name of the field type that is displayed in the new fields block.
  • properties: An array of properties that are configurable. Configuration of these properties is defined by hook_form_builder_properties().
  • default: A complete sample form element that will be used when a new element of this type is added to the form. Further modification of this default element may be done in hook_form_builder_element_alter().
2 functions implement hook_form_builder_element_types()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

form_builder_examples_form_builder_element_types in examples/form_builder_examples.module
Implements of hook_form_builder_element_types().
form_builder_webform_form_builder_element_types in modules/webform/form_builder_webform.module
Implements hook_form_builder_element_types().
1 invocation of hook_form_builder_element_types()
FormBuilderLoader::getElementTypeInfo in ./form_builder.classes.inc

File

./form_builder.api.php, line 72
These are the hooks that are invoked by Form Builder.

Code

function hook_form_builder_element_types($form_type, $form_id) {
  if ($form_type != 'node') {
    return;
  }
  $types = array();

  // The #type property of the field is used as the key.
  $types['textfield'] = array(
    'title' => t('Textfield'),
    // Properties that may be edited on this field type.
    'properties' => array(
      'title',
      'description',
      'field_prefix',
      'field_suffix',
      'default_value',
      'required',
      'size',
    ),
    // A complete default form element used when a new field of this type
    // is added to a form.
    'default' => array(
      '#title' => t('New textfield'),
      '#type' => 'textfield',
    ),
  );

  // Return the array of supported element types.
  return $types;
}