You are here

public function FormBuilderWebformForm::addComponents in Form Builder 7

Add components to the form.

Parameters

array $components: A components array as you would find it in $node->webform['components'].

File

modules/webform/form_builder_webform.classes.inc, line 55

Class

FormBuilderWebformForm

Code

public function addComponents($components) {
  foreach ($components as $cid => $component) {
    $element['#webform_component'] = $component;
    $element['#weight'] = $component['weight'];
    $element['#key'] = $component['form_key'];
    $parent_id = $component['pid'] ? 'cid_' . $component['pid'] : FORM_BUILDER_ROOT;
    $element['#form_builder'] = array(
      'element_id' => 'cid_' . $cid,
      'parent_id' => $parent_id,
    );
    if ($map = _form_builder_webform_property_map($component['type'])) {

      // Keep the internal type of this element as the component type. For example
      // this may match an $element['#type'] of 'webform_date' and set the
      // $element['#form_builder']['element_type'] to simply 'date'.
      if (isset($map['form_builder_type'])) {
        $element['#form_builder']['element_type'] = $map['form_builder_type'];
      }
    }
    if ($e = form_builder_webform_component_invoke($component['type'], 'form_builder_load', $element)) {
      $element = $e;
    }
    $this
      ->setElementArray($element, $parent_id);
  }
}