You are here

function template_preprocess_dropdown in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
  2. 8 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
  3. 8.2 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
  4. 8.3 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
  5. 8.4 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
  6. 8.5 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
  7. 8.6 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
  8. 8.7 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
  9. 8.8 modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
  10. 10.0.x modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
  11. 10.1.x modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()
  12. 10.2.x modules/custom/dropdown/dropdown.module \template_preprocess_dropdown()

Prepares variables for dropdown templates.

Default template: dropdown.html.twig.

Parameters

array $variables: An associative array containing:

  • element: An associative array containing the properties of the element. Properties used: #title, #value, #options, #description, #required, #attributes, #children.

File

modules/custom/dropdown/dropdown.module, line 50
Contains dropdown.module.

Code

function template_preprocess_dropdown(array &$variables) {
  $element = $variables['element'];
  $variables['attributes'] = [];
  if (isset($element['#id'])) {
    $variables['attributes']['id'] = $element['#id'];
  }
  if (isset($element['#attributes']['title'])) {
    $variables['attributes']['title'] = $element['#attributes']['title'];
  }
  $items = [];
  foreach ($element as $key => $el) {
    if (is_numeric($key) && isset($el['#type']) && $el['#type'] === 'radio') {
      $items[$key] = $el;
      if ($el['#return_value'] === $el['#value']) {

        // @todo Do we need to check for default_value also
        $selected = Html::escape($el['#title']);
        $active = $key;
      }
    }
  }
  if (isset($element['#edit_mode'])) {
    $variables['edit_mode'] = $element['#edit_mode'];
  }
  $variables['items'] = $items;
  $variables['label'] = Html::escape($element['#title']);
  $variables['selected'] = isset($selected) ? $selected : $variables['label'];
  $variables['active'] = isset($active) ? $active : 0;
  $variables['children'] = $element['#children'];
}