Skip to content
Snippets Groups Projects

Issue #3459246: Add a '#selectall' option for checkboxes element

Open Maxime Rojat-Pahud requested to merge issue/drupal-3459246:11.x into 11.x
Files
3
@@ -99,6 +99,45 @@ public static function processCheckboxes(&$element, FormStateInterface $form_sta
@@ -99,6 +99,45 @@ public static function processCheckboxes(&$element, FormStateInterface $form_sta
];
];
}
}
}
}
 
 
if (!empty($element['#check_all']) && $element['#check_all']) {
 
$element['all_wrapper'] = [
 
'#type' => 'container',
 
'#attributes' => ['class' => ['check-all']],
 
'#weight' => 0,
 
];
 
$element['all_wrapper']['check_all'] = [
 
'#type' => 'html_tag',
 
'#tag' => 'button',
 
'#value' => t('Check all'),
 
'#default_value' => FALSE,
 
'#attributes' => [
 
'class' => [
 
'check-all-btn',
 
'button--small',
 
],
 
'data-check-all' => TRUE,
 
'type' => 'button',
 
],
 
];
 
$element['all_wrapper']['uncheck_all'] = [
 
'#type' => 'html_tag',
 
'#tag' => 'button',
 
'#value' => t('Uncheck all'),
 
'#default_value' => FALSE,
 
'#attributes' => [
 
'class' => [
 
'check-all-btn',
 
'button--small',
 
],
 
'data-check-all' => FALSE,
 
'type' => 'button',
 
],
 
];
 
 
$element['#attached']['library'][] = 'core/drupal.check-all';
 
}
 
return $element;
return $element;
}
}
Loading