You are here

function tablesorter_page_attachments in Tablesorter 8

Same name and namespace in other branches
  1. 3.0.x tablesorter.module \tablesorter_page_attachments()

Implements hook_page_attachments().

File

./tablesorter.module, line 22
tablesorter.

Code

function tablesorter_page_attachments(array &$page) {
  $config = \Drupal::config('tablesorter.settings');
  $theme = $config
    ->get('tablesorter_theme');

  // Set JS variables.
  $zebra = $config
    ->get('tablesorter_zebra');
  $odd_class = $config
    ->get('tablesorter_zebra_odd_class');
  $even_class = $config
    ->get('tablesorter_zebra_even_class');

  // Attach Tablesorter library to all pages.
  $page['#attached']['library'][] = 'tablesorter/mottie.tablesorter';
  $settings = [
    'zebra' => $zebra,
    'odd' => $odd_class,
    'even' => $even_class,
  ];
  $page['#attached']['drupalSettings']['tablesorter'] = $settings;
  switch ($theme) {
    case 'blue':
      $page['#attached']['library'][] = 'tablesorter/tablesorter.blue';
      break;
    case 'green':
      $page['#attached']['library'][] = 'tablesorter/tablesorter.green';
      break;
  }
}