You are here

function template_preprocess_webform_section in Webform 8.5

Same name and namespace in other branches
  1. 6.x includes/webform.theme.template.inc \template_preprocess_webform_section()

Prepares variables for webform section element templates.

Default template: webform-section.html.twig.

Copied from: template_preprocess_fieldset()

Parameters

array $variables: An associative array containing:

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

File

includes/webform.theme.template.inc, line 713
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_webform_section(array &$variables) {
  $element = $variables['element'];
  Element::setAttributes($element, [
    'id',
  ]);
  RenderElement::setAttributes($element);
  $variables['attributes'] = isset($element['#attributes']) ? $element['#attributes'] : [];
  $variables['prefix'] = isset($element['#field_prefix']) ? $element['#field_prefix'] : NULL;
  $variables['suffix'] = isset($element['#field_suffix']) ? $element['#field_suffix'] : NULL;
  $variables['title_display'] = isset($element['#title_display']) ? $element['#title_display'] : NULL;
  $variables['title_tag'] = isset($element['#title_tag']) ? $element['#title_tag'] : 'h2';
  $variables['title_attributes'] = isset($element['#title_attributes']) ? $element['#title_attributes'] : [];
  $variables['description_display'] = isset($element['#description_display']) ? $element['#description_display'] : 'before';
  $variables['children'] = $element['#children'];
  $variables['required'] = !empty($element['#required']) ? $element['#required'] : NULL;

  // Allow markup in title.
  if (isset($element['#title']) && $element['#title'] !== '') {
    $variables['title'] = [
      '#markup' => $element['#title'],
    ];
  }

  // Add 'visually-hidden' class to title attributes.
  if ($variables['title_display'] === 'invisible') {
    $variables['title_attributes']['class'][] = 'visually-hidden';
  }
  $variables['title_attributes'] = new Attribute($variables['title_attributes']);
  if (!empty($element['#description'])) {
    $description_id = $element['#attributes']['id'] . '--description';
    $description_attributes['id'] = $description_id;
    $variables['description']['attributes'] = new Attribute($description_attributes);
    $variables['description']['content'] = $element['#description'];

    // Add the description's id to the fieldset aria attributes.
    $variables['attributes']['aria-describedby'] = $description_id;
  }

  // Suppress error messages.
  $variables['errors'] = NULL;

  // Setup description, help, and more.
  _webform_preprocess_element($variables);
}