You are here

function theme_form_builder_field_palette in Form Builder 7

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

Block for adding new fields.

Parameters

$vars['fields']: A list of all fields can be added to the current form type.

$vars['groups']: A list of groups that fields may be sorted into. Each field is assigned a 'palette_group' property which corresponds to one of these groups.

$vars['form_type']: The form type to which these blocks apply.

$vars['form_id']: The form ID that is being edited.

1 theme call to theme_form_builder_field_palette()
form_builder_field_palette in includes/form_builder.admin.inc
Render the palette of fields to add to a form.

File

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

Code

function theme_form_builder_field_palette($vars) {
  extract($vars);
  $output = '';
  $lists = array();
  foreach ($fields as $field_name => $field) {
    $class = array(
      'field-' . $field_name,
      'form-builder-palette-element',
    );
    $style = '';

    // If a field is unique, add a special class to identify it.
    if ($field['unique']) {
      $class[] = 'form-builder-unique';
      $class[] = 'form-builder-element-' . $field_name;

      // If already in use, do not display it in the list.
      if (!empty($field['in_use'])) {
        $style = 'display: none;';
      }
    }
    $lists[$field['palette_group']]['#weight'] = $groups[$field['palette_group']]['weight'];
    $lists[$field['palette_group']][] = array(
      'data' => l($field['title'], 'admin/structure/form-builder/add/' . $form_type . '/' . $form_id . '/' . $field_name, array(
        'query' => drupal_get_destination(),
      )),
      'class' => $class,
      'style' => $style,
    );
  }

  // Sort the lists by weight.
  uasort($lists, 'element_sort');
  $output .= '<div id="form-builder-field-palette">';
  foreach ($lists as $group => $list) {
    unset($list['#weight']);
    $output .= theme('item_list', array(
      'items' => $list,
      'title' => count($lists) > 1 ? $groups[$group]['title'] : t('Add a field'),
      'type' => 'ul',
      'attributes' => array(
        'class' => array(
          'form-builder-fields',
          'clearfix',
        ),
      ),
    ));
  }
  $output .= '</div>';
  return $output;
}