1 field.theme.inc theme_field_multiple_value_form($variables)

Returns HTML for an individual form element.

Combine multiple values into a table with drag-n-drop reordering. TODO : convert to a template.

Parameters

$variables: An associative array containing:

  • element: A render element representing the form element.

Related topics

File

core/modules/field/field.theme.inc, line 100
Theme functions for the Field module.

Code

function theme_field_multiple_value_form($variables) {
  $element = $variables['element'];
  $output = '';

  if ($element['#cardinality'] > 1 || $element['#cardinality'] == FIELD_CARDINALITY_UNLIMITED) {
    $table_id = backdrop_html_id($element['#field_name'] . '_values');
    $order_class = $element['#field_name'] . '-delta-order';
    $required = !empty($element['#required']) ? theme('form_required_marker', $variables) : '';

    $header = array(
      array(
        'data' => '<label>' . t('!title !required', array('!title' => $element['#title'], '!required' => $required)) . "</label>",
        'colspan' => 2,
        'class' => array('field-label'),
      ),
      t('Order'),
    );
    $rows = array();

    if ($element['#description']) {
      $description = '<div class="description">' . $element['#description'] . '</div>';
      $rows[] = array(
        'data' => array(
          array('data' => ''),
          array('data' => $description, 'colspan' => 3),
        ),
      );
    }

    // Sort items according to '_weight' (needed when the form comes back after
    // preview or failed validation)
    $items = array();
    foreach (element_children($element) as $key) {
      if ($key === 'add_more') {
        $add_more_button = &$element[$key];
      }
      else {
        $items[] = &$element[$key];
      }
    }
    usort($items, '_field_sort_items_value_helper');

    // Add the items as table rows.
    foreach ($items as $key => $item) {
      $item['_weight']['#attributes']['class'] = array($order_class);
      $delta_element = backdrop_render($item['_weight']);
      $cells = array(
        array('data' => '', 'class' => array('field-multiple-drag')),
        backdrop_render($item),
        array('data' => $delta_element, 'class' => array('delta-order')),
      );
      $rows[] = array(
        'data' => $cells,
        'class' => array('draggable'),
      );
    }

    $add_more = backdrop_render($add_more_button);
    $rows[] = array(
      'data' => array(
        array('data' => ''),
        array('data' => $add_more, 'colspan' => 2),
      ),
    );

    $output = '<div class="form-item">';
    $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => $table_id, 'class' => array('field-multiple-table'))));
    $output .= '</div>';

    backdrop_add_tabledrag($table_id, 'order', 'sibling', $order_class);
  }
  else {
    foreach (element_children($element) as $key) {
      $output .= backdrop_render($element[$key]);
    }
  }

  return $output;
}