You are here

function theme_views_node_selector in Views Bulk Operations (VBO) 5

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

Theme function for the views_node_selector form element

Display the nodes of a view as a form in a table with radios or checkboxes.

File

./views_form.inc, line 13
Helper functions for the views_node_selector form element type.

Code

function theme_views_node_selector($element) {
  drupal_add_js(drupal_get_path('module', 'views_bulk_operations') . '/views_bulk_operations.js');
  $fields = _views_get_fields();
  $view = $element['#view'];
  $multiple = $element['#multiple'];
  $output = '';

  // Make sure we have the table header.
  if (!isset($view->table_header)) {
    $view->table_header = _views_construct_header($view, $fields);
  }

  // Add CSS classes for the whole form.
  $class = 'views-form ' . ($element['#multiple'] ? 'views-form-multiple' : 'views-form-single');
  if (isset($element['#attributes']['class'])) {
    $class .= ' ' . $element['#attributes']['class'];
  }
  $output .= '<div class = "' . $class . '">';
  if (!empty($element['#view_nodes']) && is_array($element['#view_nodes'])) {
    $rows = array();
    foreach ($element['#view_nodes'] as $node) {
      $arow = array();
      $arow[] = array(
        'data' => $multiple ? theme('checkbox', $element[$node->nid]) : theme('radio', $element[$node->nid]),
      );
      foreach ($view->field as $field) {
        if ($fields[$field['id']]['visible'] !== FALSE) {
          $cell['data'] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
          $cell['class'] = "view-field " . views_css_safe('view-field-' . $field['queryname']);
          $arow[] = $cell;
        }
      }
      $rows[] = $arow;
    }
  }
  else {
    $rows[] = array(
      array(
        'data' => t('No posts available.'),
        'colspan' => count($view->table_header) + 1,
      ),
    );
  }

  // Add a column to the header to accomodate our selection column, and include
  // the 'select all' checkbox if we are using checkboxes.
  $extra = $multiple ? theme('table_select_header_cell') : '&nbsp;';
  if (is_array($view->table_header)) {
    array_unshift($view->table_header, $extra);
  }

  // Add the first row as option to select all records across all pages.
  if ($view->use_pager) {
    $arow = array(
      array(
        'data' => '<span id="vbo-this-page">' . t('All <strong>!nodes</strong> nodes on this page are selected.', array(
          '!nodes' => count($element['#view_nodes']),
        )) . '&nbsp;<input type="button" id="vbo-select-all-pages" value="' . t('Select all !nodes nodes in this view.', array(
          '!nodes' => $view->total_rows,
        )) . '" /></span>' . '<span id="vbo-all-pages" style="display: none">' . t('All <strong>!nodes</strong> nodes in this view are selected.', array(
          '!nodes' => $view->total_rows,
        )) . '&nbsp;<input type="button" id="vbo-select-this-page" value="' . t('Select only !nodes nodes on this page.', array(
          '!nodes' => count($element['#view_nodes']),
        )) . '" /></span>',
        'class' => 'view-field view-field-select-all',
        'colspan' => count($view->table_header) + 1,
      ),
    );
    array_unshift($rows, $arow);
  }
  $output .= theme('views_form_table', $view->table_header, $rows);
  $output .= theme('hidden', $element['select_all']);
  $output .= '</div>';
  return theme('form_element', $element, $output);
}