You are here

function draggableviews_preprocess_views_view_table in DraggableViews 8

Same name and namespace in other branches
  1. 7.2 draggableviews.module \draggableviews_preprocess_views_view_table()
  2. 2.0.x draggableviews.module \draggableviews_preprocess_views_view_table()

Implements hook_preprocess_views_view_table().

File

./draggableviews.module, line 84
Contains draggableviews.module.

Code

function draggableviews_preprocess_views_view_table(&$variables) {
  $view = $variables['view'];

  // If this view is not the sort view, then stop here.
  if (!isset($view->field['draggableviews'])) {
    return;
  }
  $draggableviews = new DraggableViews($variables['view']);

  // Add hierarchy.
  foreach ($variables['rows'] as $key => $row) {
    $columns = array_keys($row['columns']);

    // Find the first column that is not the draggableviews field.
    foreach ($columns as $first_column) {
      if ($first_column !== 'draggableviews') {
        break;
      }
    }

    // Indent the first column that is not the draggableviews field.
    $columns_title = $row['columns'][$first_column]['content'][0]['field_output']['#markup'];
    $indent = [
      '#theme' => 'indentation',
      '#size' => $draggableviews
        ->getDepth($key),
    ];
    $variables['rows'][$key]['columns'][$first_column]['content'][0]['field_output']['#markup'] = (string) (render($indent) . $columns_title);
  }

  // Add table attributes.
  $variables['attributes']['id'] = $draggableviews
    ->getHtmlId();

  // Add rows attributes.
  foreach ($variables['rows'] as &$row) {
    $row['attributes']
      ->addClass('draggable');
  }
  unset($row);
}