You are here

function template_preprocess_webform_card in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_cards/webform_cards.module \template_preprocess_webform_card()

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

modules/webform_cards/webform_cards.module, line 586
Provides a 'Card' container element for clientside multistep form pagination.

Code

function template_preprocess_webform_card(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['children'] = $element['#children'];

  // 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;
  }

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