You are here

views_table_rowspan.module in Views Table Rowspan 8

Same filename and directory in other branches
  1. 7 views_table_rowspan.module

Merge duplicate rows in group to one row.

File

views_table_rowspan.module
View source
<?php

/**
 * @file
 * Merge duplicate rows in group to one row.
 */
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;

/**
 * Implements hook_help().
 */
function views_table_rowspan_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match) {
  $link = Link::fromTextAndUrl('new view', Url::fromUserInput("/admin/structure/views/add"))
    ->toString();
  $rowspan_link = Link::fromTextAndUrl('rowspan', Url::fromUri("http://www.w3schools.com/tags/att_td_rowspan.asp"))
    ->toString();
  switch ($route_name) {

    // Help for module views_table_rowspan.
    case 'help.page.views_table_rowspan':
      $help = '<p>' . t('Views Table Rowspan defines new views display format name "Table Rowspan". This display will group rows in table and merge row has same value to one row use property @url.', [
        '@url' => $rowspan_link,
      ]) . '</p>';
      $help .= '<ul>';
      $help .= '<li>' . t('Create a @link (for example, a list of node).', [
        '@link' => $link,
      ]) . '</li>';
      $help .= '<li>' . t('Set format Table Rowspan for this view.') . '</li>';
      $help .= '<li>' . t('Add some field to this view.') . '</li>';
      $help .= '<li>' . t('Group field that has same value.') . '</li>';
      $help .= '<li>' . t('Check option "Merge rows in group".') . '</li>';
      $help .= '</ul>';
      return $help;
  }
}

/**
 * Implements hook_preprocess_hook().
 *
 * @internal
 */
function views_table_rowspan_preprocess_views_view_table(&$vars) {
  $view = $vars['view'];
  if (isset($view->rowspan)) {
    foreach ($view->rowspan as $field_name => $rowspan) {
      foreach ($rowspan as $row_index => $num_span) {

        /** @var \Drupal\Core\Template\Attribute $attributes */
        $attributes =& $vars['rows'][$row_index]['columns'][$field_name]['attributes'];
        $attributes
          ->setAttribute('rowspan', count($num_span));
        $attributes
          ->addClass('cell-rowspan');

        // Hide other columns.
        array_shift($num_span);
        foreach ($num_span as $row_span_index) {
          $attributes =& $vars['rows'][$row_span_index]['columns'][$field_name]['attributes'];
          $attributes
            ->setAttribute('style', 'display:none');
        }
      }
    }
  }
}

Functions

Namesort descending Description
views_table_rowspan_help Implements hook_help().
views_table_rowspan_preprocess_views_view_table Implements hook_preprocess_hook().