function responsive_tables_filter_preprocess_views_view_table in Responsive Tables Filter 8
Same name and namespace in other branches
- 7 responsive_tables_filter.module \responsive_tables_filter_preprocess_views_view_table()
Implements template_preprocess_views_view_table().
Adds tablesaw JS when tables present and CSS/JS aggregation is off to table.
File
- ./
responsive_tables_filter.module, line 49 - Contains responsive_tables_filter.module..
Code
function responsive_tables_filter_preprocess_views_view_table(&$variables) {
$config = \Drupal::config('responsive_tables_filter.settings');
if ($config
->get('views_enabled')) {
$mode = $config
->get('views_tablesaw_mode');
// Add shared tablesaw classes & data attribute.
// Only apply attributes if the View has not already specified classes,
// to allow sites to be able to override the tablesaw behavior on a per
// View basis.
if (empty($variables['attributes']['class'])) {
$variables['attributes']['class'][] = 'tablesaw';
$variables['attributes']['class'][] = 'tablesaw-' . $mode;
}
// Add required columntoggle- & swipe- specific attributes.
if (in_array($mode, [
'columntoggle',
'swipe',
])) {
$inc = 1;
foreach (array_keys($variables['header']) as $key) {
$variables['header'][$key]['attributes']['data-tablesaw-sortable-col'] = '';
$variables['header'][$key]['attributes']['data-tablesaw-priority'] = $inc;
}
$inc++;
}
$variables['attributes']['data-tablesaw-mode'][] = $mode;
$variables['view']->element['#attached']['library'][] = 'responsive_tables_filter/tablesaw-filter';
$variables['#cache']['tags'][] = 'config:responsive_tables_filter.settings';
}
}