You are here

function theme_views_node_selector in Views Bulk Operations (VBO) 6

Same name and namespace in other branches
  1. 5 views_form.inc \theme_views_node_selector()
  2. 6.3 views_bulk_operations.module \theme_views_node_selector()

Theme function for 'views_node_selector'.

File

./views_bulk_operations.module, line 353
Allows operations to be performed on items selected in a view.

Code

function theme_views_node_selector($element) {
  module_load_include('inc', 'views', 'theme/theme');
  $output = '';
  $view = $element['#view'];
  $sets = $element['#sets'];
  $vars = array(
    'view' => $view,
  );

  // Give each group its own headers row.
  foreach ($sets as $title => $records) {
    $headers = array();

    // template_preprocess_views_view_table() expects the raw data in 'rows'.
    $vars['rows'] = $records;

    // Render the view as table. Use the hook from from views/theme/theme.inc
    // and allow overrides using the same algorithm as the theme system will
    // do calling the theme() function.
    $hook = 'views_view_table';
    $hooks = theme_get_registry();
    if (!isset($hooks[$hook])) {
      return '';
    }
    $args = array(
      &$vars,
      $hook,
    );
    foreach ($hooks[$hook]['preprocess functions'] as $func) {
      if (function_exists($func)) {
        call_user_func_array($func, $args);
      }
    }

    // Add checkboxes to the header and the rows.
    $rows = array();
    if (empty($view->style_plugin->options['hide_selector'])) {
      $headers[] = array(
        'class' => 'vbo-select-all',
      );

      // Add extra status row if needed.
      $items_per_page = method_exists($view, 'get_items_per_page') ? $view
        ->get_items_per_page() : (isset($view->pager) ? $view->pager['items_per_page'] : 0);
      if ($items_per_page && $view->total_rows > $items_per_page) {
        $row = theme('views_bulk_operations_select_all', count($vars['header']) + 1, _views_bulk_operations_get_selection_count($view->style_plugin, $element['#default_value']), $view);
        $rows[] = $row;
      }
    }
    else {
      $headers[] = array(
        'class' => 'no-select-all',
      );
    }
    foreach ($vars['header'] as $field => $label) {
      $headers[] = array(
        'data' => $label,
        'class' => "views-field views-field-{$vars['fields'][$field]}",
      );
    }
    foreach ($records as $num => $object) {
      $vars['row_classes'][$num][] = 'rowclick';
      $row = array(
        'class' => implode(' ', $vars['row_classes'][$num]),
        'data' => array(),
      );
      $row['data'][] = theme('checkbox', $element['selection'][_views_bulk_operations_hash_object($object, $view)]);
      foreach ($vars['rows'][$num] as $field => $content) {

        // Support field classes in Views 3, but provide a fallback for Views 2.
        if (views_api_version() == 2) {
          $row['data'][] = array(
            'data' => $content,
            'class' => 'views-field views-field-' . $vars['fields'][$field],
          );
        }
        else {
          $row['data'][] = array(
            'data' => $content,
            'class' => $vars['field_classes'][$field][$num],
          );
        }
      }
      $rows[] = $row;
    }
    $theme_functions = views_theme_functions('views_bulk_operations_table', $view, $view->display[$view->current_display]);
    $output .= theme($theme_functions, $headers, $rows, array(
      'class' => $vars['class'],
    ), $title, $view);
    $output .= theme('hidden', $element['selectall']);
  }
  return theme('form_element', $element, $output);
}