function template_preprocess_yamlform_progress in YAML Form 8
Prepares variables for form 'wizard' progress template.
Default template: yamlform-progress.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 506 - Preprocessors and helper functions to make theming easier.
Code
function template_preprocess_yamlform_progress(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];
$total = count($page_keys);
if ($yamlform
->getSetting('wizard_progress_bar')) {
$variables['bar'] = [
'#theme' => 'yamlform_progress_bar',
'#yamlform' => $variables['yamlform'],
'#current_page' => $variables['current_page'],
];
}
if ($yamlform
->getSetting('wizard_progress_pages')) {
$variables['summary'] = t('Page @start of @end', [
'@start' => $current_index + 1,
'@end' => $total,
]);
}
if ($yamlform
->getSetting('wizard_progress_percentage')) {
$variables['percentage'] = number_format($current_index / ($total - 1) * 100, 0) . '%';
}
}