You are here

function form_builder_field_render in Form Builder 7

Same name and namespace in other branches
  1. 6 includes/form_builder.admin.inc \form_builder_field_render()
  2. 7.2 includes/form_builder.admin.inc \form_builder_field_render()

Render a single field independent of other settings.

@todo form rendering a form method.

2 calls to form_builder_field_render()
form_builder_field_json in includes/form_builder.admin.inc
Menu callback to display a field as a JSON string.
_form_builder_add_element in includes/form_builder.admin.inc
Menu callback helper for adding or cloning a field.

File

includes/form_builder.admin.inc, line 716
form_builder.admin.inc Administrative interface for editing forms.

Code

function form_builder_field_render($form_type, $form_id, $element_id, $wrapper = FALSE) {
  module_load_include('inc', 'form_builder', 'includes/form_builder.api');
  module_load_include('inc', 'form_builder', 'includes/form_builder.cache');

  // Load the current state of the form and prepare it for rendering.
  $loader = FormBuilderLoader::instance();
  $form_obj = $loader
    ->fromCache($form_type, $form_id);
  if (!$form_obj) {
    $form_obj = $loader
      ->fromStorage($form_type, $form_id);
    $form_obj
      ->save();
  }
  $form_state = array(
    'submitted' => FALSE,
    'build_info' => array(
      'args' => array(
        $form_obj,
        $form_type,
        $form_id,
      ),
    ),
    'values' => array(),
    'method' => 'get',
  );
  $form = drupal_retrieve_form('form_builder_preview', $form_state);
  drupal_prepare_form('form_builder_preview', $form, $form_state);
  $form['#post'] = array();
  $form = form_builder('form_builder_preview', $form, $form_state);

  // Get only the element wanted and render it.
  $element = form_builder_get_element($form, $element_id);
  if ($wrapper) {
    $element['#theme_wrappers'][] = 'form_builder_element_wrapper';
  }
  return drupal_render($element);
}