function theme_styleswitcher_admin_styles_table in Style Switcher 8.2
Same name and namespace in other branches
- 6.2 styleswitcher.admin.inc \theme_styleswitcher_admin_styles_table()
- 7.2 styleswitcher.admin.inc \theme_styleswitcher_admin_styles_table()
- 3.0.x styleswitcher.module \theme_styleswitcher_admin_styles_table()
Returns HTML for the styles settings overview form element.
Parameters
array $variables: An associative array containing:
- form: An element representing the form.
1 string reference to 'theme_styleswitcher_admin_styles_table'
- styleswitcher_theme in ./
styleswitcher.module - Implements hook_theme().
1 theme call to theme_styleswitcher_admin_styles_table()
- StyleswitcherConfigTheme::buildForm in src/
Form/ StyleswitcherConfigTheme.php - Form constructor.
File
- ./
styleswitcher.module, line 455 - Module's hooks implementations and helper functions.
Code
function theme_styleswitcher_admin_styles_table(array $variables) {
$form = $variables['form'];
$header = [
t('Style'),
t('Enabled'),
t('Default'),
t('Weight'),
];
$rows = [];
if (!empty($form['weight'])) {
foreach (Element::children($form['weight']) as $key) {
if ($key == $form['default']['#default_value']) {
$form['enabled'][$key]['#attributes']['disabled'] = 'disabled';
}
$label = $form['label'][$key]['#markup'];
$form['enabled'][$key]['#title'] = t('Enable @title', [
'@title' => $label,
]);
$form['enabled'][$key]['#title_display'] = 'invisible';
$form['default'][$key]['#title'] = t('Set @title as default', [
'@title' => $label,
]);
$form['default'][$key]['#title_display'] = 'invisible';
// Build the table row.
$row = [
[
'data' => $form['name'][$key],
],
[
'data' => $form['enabled'][$key],
],
[
'data' => $form['default'][$key],
],
[
'data' => $form['weight'][$key],
],
];
$rows[] = [
'data' => $row,
'class' => [
'draggable',
],
];
}
}
$table = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No styles to switch.'),
'#attributes' => [
'id' => 'styleswitcher-styles-table',
],
'#tabledrag' => [
0 => [
'action' => 'order',
'relationship' => 'sibling',
'group' => 'styleswitcher-style-weight',
],
],
];
return Drupal::service('renderer')
->render($table);
}