You are here

function theme_checkbox_tree in Taxonomy Term Reference Tree Widget 8

Same name and namespace in other branches
  1. 7.2 term_reference_tree.widget.inc \theme_checkbox_tree()
  2. 7 term_reference_tree.widget.inc \theme_checkbox_tree()

Returns HTML for a checkbox_tree form element.

1 string reference to 'theme_checkbox_tree'
term_reference_tree_theme in ./term_reference_tree.module
Implements hook_theme().
1 theme call to theme_checkbox_tree()
CheckboxTree::getInfo in src/Element/CheckboxTree.php
Returns the element properties for this element.

File

./term_reference_tree.module, line 40

Code

function theme_checkbox_tree($variables) {
  $element = $variables['element'];
  foreach (Element::children($element) as $key) {

    // Early rendering to collect the wrapper attributes from
    // ToolbarItem elements.
    if (!empty($element[$key])) {
      $element['#children'] = \Drupal::service('renderer')
        ->render($element[$key]);
    }
  }
  $attributes = isset($element['#attributes']) ? $element['#attributes'] : [];
  if (isset($element['#id'])) {
    $attributes['id'] = $element['#id'];
  }
  $attributes['class'][] = 'term-reference-tree';
  if (!empty($element['#required'])) {
    $attributes['class'][] = 'required';
  }
  if (array_key_exists('#start_minimized', $element) && $element['#start_minimized']) {
    $attributes['class'][] = 'term-reference-tree-collapsed';
  }
  if (array_key_exists('#track_list', $element) && $element['#track_list']) {
    $attributes['class'][] = 'term-reference-tree-track-list-shown';
  }
  if (!empty($variables['element']['#select_parents'])) {
    $attributes['class'][] = 'term-reference-tree-select-parents';
  }
  if ($variables['element']['#cascading_selection'] != TermReferenceTree::CASCADING_SELECTION_NONE) {
    $attributes['class'][] = 'term-reference-tree-cascading-selection';
  }
  if ($variables['element']['#cascading_selection'] == TermReferenceTree::CASCADING_SELECTION_SELECT) {
    $attributes['class'][] = 'term-reference-tree-cascading-selection-mode-select';
  }
  else {
    if ($variables['element']['#cascading_selection'] == TermReferenceTree::CASCADING_SELECTION_DESELECT) {
      $attributes['class'][] = 'term-reference-tree-cascading-selection-mode-deselect';
    }
  }
  if (!empty($element['#attributes']['class'])) {
    $attributes['class'] = array_merge($attributes['class'], $element['#attributes']['class']);
  }
  return '<div' . new Attribute($attributes) . '>' . (!empty($element['#children']) ? $element['#children'] : '') . '</div>';
}