You are here

function template_preprocess_webform_progress in Webform 6.x

Same name and namespace in other branches
  1. 8.5 includes/webform.theme.template.inc \template_preprocess_webform_progress()

Prepares variables for webform 'wizard' progress templates.

Default template: webform-progress.html.twig.

Parameters

array $variables: An associative array containing the following key:

  • webform: A webform.
  • current_page: The current wizard page.
1 call to template_preprocess_webform_progress()
template_preprocess_webform_progress__test_cards_progress_custom in modules/webform_cards/tests/modules/webform_cards_test/webform_cards_test.module
Prepares variables for webform 'wizard' progress templates.

File

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

Code

function template_preprocess_webform_progress(array &$variables) {

  /** @var \Drupal\webform\WebformLibrariesManagerInterface $libraries_manager */
  $libraries_manager = \Drupal::service('webform.libraries_manager');

  /** @var \Drupal\webform\WebformInterface $webform */
  $webform = $variables['webform'];

  /** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */
  $webform_submission = $variables['webform_submission'];
  $current_page = $variables['current_page'];
  $operation = $variables['operation'];
  $pages = $variables['pages'] ?: $webform
    ->getPages($operation, $webform_submission);
  $page_keys = array_keys($pages);
  $page_indexes = array_flip($page_keys);
  $current_index = $page_indexes[$current_page];
  $total = count($page_keys);
  $variables['index'] = $current_index + 1;
  $variables['total'] = $total;
  if ($webform
    ->getSetting('wizard_progress_bar')) {
    $variables['bar'] = [
      '#theme' => $libraries_manager
        ->isIncluded('progress-tracker') ? 'webform_progress_tracker' : 'webform_progress_bar',
      '#webform' => $webform,
      '#webform_submission' => $webform_submission,
      '#current_page' => $current_page,
      '#operation' => $operation,
      '#pages' => $variables['pages'],
    ];
  }
  if ($webform
    ->getSetting('wizard_progress_pages')) {
    $variables['summary'] = t('@start of @end', [
      '@start' => $current_index + 1,
      '@end' => $total,
    ]);
  }
  if ($webform
    ->getSetting('wizard_progress_percentage')) {
    $variables['percentage'] = number_format($current_index / ($total - 1) * 100, 0) . '%';
  }
}