You are here

function theme_views_dynamic_fields_sort_filter_fields in Views Dynamic Fields 7

Theme a drag-sortable table of fields in the exposed filter.

File

./views_dynamic_fields.module, line 60
Registers a views filter.

Code

function theme_views_dynamic_fields_sort_filter_fields($variables) {
  $form = $variables['form'];
  drupal_add_tabledrag('views-dynamic-fields-filters-table-sort', 'order', 'self', 'sort');

  // Weight for sortable tables.
  // @see http://drupal.org/node/935910
  // @see https://www.drupal.org/node/2327893
  $header = array(
    t('Select'),
    t('Field'),
    t('Weight'),
  );
  $rows = array();
  foreach (element_children($form) as $key) {

    // This is important.
    // We need to start with an empty element for the drag handle.
    $row = array();

    // Add class to group weight fields for drag and drop.
    $form[$key]['sort']['#attributes']['class'] = array(
      'sort',
    );
    $row[] = drupal_render($form[$key]['check']);
    $row[] = drupal_render($form[$key]['title']);
    $row[] = drupal_render($form[$key]['sort']);

    // Note the difference between $row and $rows.
    $rows[] = array(
      'data' => $row,
      'class' => array(
        'draggable',
      ),
    );
  }
  $output = theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'id' => 'views-dynamic-fields-filters-table-sort',
    ),
  ));
  $output .= drupal_render_children($form);
  return $output;
}