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 bar & tracker templates.

Parameters

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

  • webform: A webform.
  • current_page: The current wizard page.
3 calls to _template_preprocess_webform_progress()
template_preprocess_webform_progress_bar in includes/webform.theme.template.inc
Prepares variables for webform 'wizard' progress bar templates.
template_preprocess_webform_progress_tracker in includes/webform.theme.template.inc
Prepares variables for webform 'wizard' progress tracker templates.
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 601
Preprocessors and helper functions to make theming easier.

Code

function _template_preprocess_webform_progress(array &$variables) {

  /** @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];
  $variables['current_index'] = $current_index;

  // Reset the pages variable.
  $variables['progress'] = [];
  foreach ($pages as $key => $page) {
    $variables['progress'][] = [
      'name' => $key,
      'title' => isset($page['#title']) ? $page['#title'] : '',
      'type' => isset($page['#type']) ? $page['#type'] : 'page',
    ];
  }
}