function template_preprocess_yamlform_progress_bar in YAML Form 8
Prepares variables for form 'wizard' progress bar template.
Default template: yamlform-progress-bar.html.twig.
Parameters
array $variables: An associative array containing the following key:
- yamlform: A form.
- current_page: The current wizard page.
File
- includes/
yamlform.theme.inc, line 546 - Preprocessors and helper functions to make theming easier.
Code
function template_preprocess_yamlform_progress_bar(array &$variables) {
/** @var \Drupal\yamlform\YamlFormInterface $yamlform */
$yamlform = $variables['yamlform'];
$current_page = $variables['current_page'];
$pages = $yamlform
->getPages();
$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 $page) {
$variables['progress'][] = isset($page['#title']) ? $page['#title'] : '';
}
}