function claro_preprocess_file_widget_multiple
Same name in other branches
- 9 core/themes/claro/claro.theme \claro_preprocess_file_widget_multiple()
- 10 core/themes/claro/claro.theme \claro_preprocess_file_widget_multiple()
- 11.x core/themes/claro/claro.theme \claro_preprocess_file_widget_multiple()
Implements hook_preprocess_HOOK() for file_widget_multiple.
File
-
core/
themes/ claro/ claro.theme, line 1107
Code
function claro_preprocess_file_widget_multiple(&$variables) {
$has_upload = FALSE;
if (isset($variables['table']['#type']) && $variables['table']['#type'] === 'table') {
// Add a variant class for the table.
$variables['table']['#attributes']['class'][] = 'table-file-multiple-widget';
// Mark table disabled if the field widget is disabled.
if (isset($variables['element']['#disabled']) && $variables['element']['#disabled']) {
$variables['table']['#attributes']['class'][] = 'tabledrag-disabled';
$variables['table']['#attributes']['class'][] = 'js-tabledrag-disabled';
// We will add the 'is-disabled' CSS class to the disabled table header
// cells.
foreach ($variables['table']['#header'] as &$cell) {
if (is_array($cell) && isset($cell['data'])) {
$cell = $cell + [
'class' => [],
];
$cell['class'][] = 'is-disabled';
}
else {
// We have to modify the structure of this header cell.
$cell = [
'data' => $cell,
'class' => [
'is-disabled',
],
];
}
}
}
// Mark operations column cells with a CSS class.
if (isset($variables['table']['#rows']) && is_array($variables['table']['#rows'])) {
foreach ($variables['table']['#rows'] as $row_key => $row) {
if (isset($row['data']) && is_array($row['data'])) {
$last_cell = end($row['data']);
$last_cell_key = key($row['data']);
if (is_array($last_cell['data'])) {
foreach ($last_cell['data'] as $last_cell_item) {
if (isset($last_cell_item['#attributes']['class']) && is_array($last_cell_item['#attributes']['class']) && in_array('remove-button', $last_cell_item['#attributes']['class'])) {
$variables['table']['#rows'][$row_key]['data'][$last_cell_key] += [
'class' => [],
];
$variables['table']['#rows'][$row_key]['data'][$last_cell_key]['class'][] = 'file-operations-cell';
break 1;
}
}
}
}
}
}
// Add a CSS class to the table if an upload widget is present.
// This is required for removing the border of the last table row.
if (!empty($variables['element'])) {
$element_keys = Element::children($variables['element']);
foreach ($element_keys as $delta) {
if (!isset($variables['element'][$delta]['upload']['#access']) || $variables['element'][$delta]['upload']['#access'] !== FALSE) {
$has_upload = TRUE;
break 1;
}
}
}
$variables['table']['#attributes']['class'][] = $has_upload ? 'table-file-multiple-widget--has-upload' : 'table-file-multiple-widget--no-upload';
}
$table_is_not_empty = isset($variables['table']['#rows']) && !empty($variables['table']['#rows']);
$table_is_accessible = !isset($variables['table']['#access']) || isset($variables['table']['#access']) && $variables['table']['#access'] !== FALSE;
$variables['has_table'] = $table_is_not_empty && $table_is_accessible;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.