Problem/Motivation

The variables announced in the template file webform-progress.html.twig are not all defined. These variables need to be made available or be removed from the template documentation. When the theme is called is pass only current_page.

{#
/**
 * @file
 * Default theme implementation for webform wizard progress.
 *
 * Available variables:
 * - webform: A webform.
 * - pages: Array of wizard pages.
 * - current_page: Current wizard page.
 * - total_pages: Current wizard page.
 * - summary: Summary of progress.
 * - percentage: Percentage completed.
 * - bar: A progress bar.
 *
 * @see template_preprocess_webform_progress()
 *
 * @ingroup themeable
 */
#}
        $form['progress'] = [
          '#theme' => 'webform_progress',
          '#webform' => $this->getWebform(),
          '#webform_submission' => $webform_submission,
          '#current_page' => $current_page,
          '#operation' => $this->operation,
          '#weight' => -20,
        ];

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#3 screenshot-webform.png38.39 KBphjou

Issue fork webform-3214745

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

phjou created an issue. See original summary.

jrockowitz’s picture

Status: Active » Needs review

The variables are set via template_preprocess_webform_progress()

/**
 * Prepares variables for webform 'wizard' progress templates.
 *
 * Default template: webform-progress.html.twig.
 *
 * @param array $variables
 *   An associative array containing the following key:
 *   - webform: A webform.
 *   - current_page: The current wizard page.
 */
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) . '%';
  }
}

Any patch that improves documentation is always welcomed

phjou’s picture

StatusFileSize
new38.39 KB

Thanks.

So it seems this is just the total_pages that is wrong. The other variables seems there. I made a merge request.

webform variables

And I also added the index one in the documentation which can be pretty useful.

  • 3efcc7a committed on 8.x-5.x
    Issue #3214745 by phjou: Progress bar template doesn't seem to match the...
jrockowitz’s picture

Status: Needs review » Fixed

  • 3efcc7a committed on 6.x
    Issue #3214745 by phjou: Progress bar template doesn't seem to match the...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.