public static function IconSelectFieldWidgetDefault::processCheckboxes in Icon Select 8
Checkbox processing.
File
- src/
Plugin/ Field/ FieldWidget/ IconSelectFieldWidgetDefault.php, line 120
Class
- IconSelectFieldWidgetDefault
- Plugin implementation of the icon_select_widget default input widget.
Namespace
Drupal\icon_select\Plugin\Field\FieldWidgetCode
public static function processCheckboxes(&$element, FormStateInterface $form_state, &$complete_form) {
$element = Checkboxes::processCheckboxes($element, $form_state, $complete_form);
if (count($element['#options']) > 0) {
foreach ($element['#options'] as $key => $choice) {
$icon['icon'] = [
'#theme' => 'icon_select_svg_icon',
'#symbol_id' => $element[$key]['#title'],
'#attributes' => [
'class' => [
'icon',
'icon--' . $element[$key]['#title'],
],
],
];
// Add title.
/** @var \Drupal\taxonomy\Entity\Term $term */
if (!empty($element['#terms'][$key])) {
$term = $element['#terms'][$key];
$element[$key]['#field_prefix'] = $term
->getName();
}
// Add markup for icon.
$element[$key]['#field_suffix'] = $icon;
// Unset title.
unset($element[$key]['#title']);
}
}
return $element;
}