function claro_preprocess_table in Drupal 9
Same name and namespace in other branches
- 8 core/themes/claro/claro.theme \claro_preprocess_table()
- 10 core/themes/claro/claro.theme \claro_preprocess_table()
Implements template_preprocess_HOOK() for table.
1 call to claro_preprocess_table()
- claro_preprocess_field_ui_table in core/
themes/ claro/ claro.theme - Implements template_preprocess_HOOK() for field_ui_table.
File
- core/
themes/ claro/ claro.theme, line 989 - Functions to support theming in the Claro theme.
Code
function claro_preprocess_table(&$variables) {
// Adding table sort indicator CSS class for inactive sort link.
// @todo Revisit after https://www.drupal.org/node/3025726 or
// https://www.drupal.org/node/1973418 is in.
if (!empty($variables['header'])) {
foreach ($variables['header'] as &$header_cell) {
if ($header_cell['content'] instanceof Link) {
$query = $header_cell['content']
->getUrl()
->getOption('query') ?: [];
if (isset($query['order']) && isset($query['sort'])) {
$header_cell['attributes']
->addClass('sortable-heading');
}
}
}
}
// Mark the whole table and the first cells if rows are draggable.
if (!empty($variables['rows'])) {
$draggable_row_found = FALSE;
foreach ($variables['rows'] as &$row) {
/** @var \Drupal\Core\Template\Attribute $row['attributes'] */
if (!empty($row['attributes']) && $row['attributes']
->hasClass('draggable')) {
if (!$draggable_row_found) {
$variables['attributes']['class'][] = 'draggable-table';
$draggable_row_found = TRUE;
}
reset($row['cells']);
$first_cell_key = key($row['cells']);
// The 'attributes' key is always here and it is an
// \Drupal\Core\Template\Attribute.
// @see template_preprocess_table();
$row['cells'][$first_cell_key]['attributes']
->addClass('tabledrag-cell');
// Check that the first cell is empty or not.
if (empty($row['cells'][$first_cell_key]) || empty($row['cells'][$first_cell_key]['content'])) {
$row['cells'][$first_cell_key]['attributes']
->addClass('tabledrag-cell--only-drag');
}
}
}
}
}