modules/acm_checkout/src/Plugin/Block/CheckoutProgressBlock.php
public function build() {
    $route_name = $this->routeMatch->getRouteName();
    if ($route_name !== 'acm_checkout.form') {
      return [];
    }

    // Load the CheckoutFlow plugin.
    $config = \Drupal::config('acm_checkout.settings');
    $checkout_flow_plugin = $config->get('checkout_flow_plugin') ?: 'multistep_default';
    $plugin_manager = \Drupal::service('plugin.manager.acm_checkout_flow');
    $checkout_flow = $plugin_manager->createInstance($checkout_flow_plugin, []);

    // Build the steps sent to the template.
    $steps = [];
    $visible_steps = array_filter($checkout_flow->getVisibleSteps(), function ($step_definition) {
      return (!isset($step_definition['hide_from_progress']));
    });
    $visible_step_ids = array_keys($visible_steps);
    $current_step_id = $checkout_flow->getStepId();
    $current_step_index = array_search($current_step_id, $visible_step_ids);

    // Get last step completed in the cart.
    $cart = $this->cartStorage;
    $cart_step_id = $cart->getCheckoutStep();
    $cart_step_index = array_search($cart_step_id, $visible_step_ids);

    $index = 0;
    foreach ($visible_steps as $step_id => $step_definition) {
      $is_link = FALSE;
      $completed = FALSE;
      if ($index < $current_step_index) {
        $position = 'previous';
      }
      elseif ($index == $current_step_index) {
        $position = 'current';
      }
      else {
        $position = 'next';
      }

      $label = $step_definition['label'];
      // Add a class if this step has been completed already.
      if ($index < $cart_step_index) {
        $completed = TRUE;
      }
      // Set the label to a link if this step has already been completed so that
      // the progress bar can be used as a sort of navigation.
      if ($index <= $cart_step_index && $index !== $current_step_index) {
        $is_link = TRUE;
        $label = Link::createFromRoute($label, 'acm_checkout.form', [
          'step' => $step_id,
        ])->toString();
      }

      $steps[] = [
        'id' => $step_id,
        'label' => $label,
        'position' => $position,
        'completed' => $completed,
        'is_link' => $is_link,
      ];

      $index++;
    }

    return [
      '#attached' => [
        'library' => ['acm_checkout/checkout_progress'],
      ],
      '#theme' => 'acm_checkout_progress',
      '#steps' => $steps,
    ];
  }
public function build() {
    $route_name = $this->routeMatch->getRouteName();
    if ($route_name !== 'acm_checkout.form') {
      return [];
    }

    // Load the CheckoutFlow plugin.
    $config = \Drupal::config('acm_checkout.settings');
    $checkout_flow_plugin = $config->get('checkout_flow_plugin') ?: 'multistep_default';
    $plugin_manager = \Drupal::service('plugin.manager.acm_checkout_flow');
    $checkout_flow = $plugin_manager->createInstance($checkout_flow_plugin, []);

    // Build the steps sent to the template.
    $steps = [];
    $visible_steps = array_filter($checkout_flow->getVisibleSteps(), function ($step_definition) {
      return (!isset($step_definition['hide_from_progress']));
    });
    $visible_step_ids = array_keys($visible_steps);
    $current_step_id = $checkout_flow->getStepId();
    $current_step_index = array_search($current_step_id, $visible_step_ids);

    // Get last step completed in the cart.
    $cart = $this->cartStorage;
    $cart_step_id = $cart->getCheckoutStep();
    $cart_step_index = array_search($cart_step_id, $visible_step_ids);

    $index = 0;
    foreach ($visible_steps as $step_id => $step_definition) {
      $is_link = FALSE;
      $completed = FALSE;
      if ($index < $current_step_index) {
        $position = 'previous';
      }
      elseif ($index == $current_step_index) {
        $position = 'current';
      }
      else {
        $position = 'next';
      }

      $label = $step_definition['label'];
      // Add a class if this step has been completed already.
      if ($index < $cart_step_index) {
        $completed = TRUE;
      }
      // Set the label to a link if this step has already been completed so that
      // the progress bar can be used as a sort of navigation.
      if ($index <= $cart_step_index && $index !== $current_step_index) {
        $is_link = TRUE;
        $label = Link::createFromRoute($label, 'acm_checkout.form', [
          'step' => $step_id,
        ])->toString();
      }

      $steps[] = [
        'id' => $step_id,
        'label' => $label,
        'position' => $position,
        'completed' => $completed,
        'is_link' => $is_link,
      ];

      $index++;
    }

    return [
      '#attached' => [
        'library' => ['acm_checkout/checkout_progress'],
      ],
      '#theme' => 'acm_checkout_progress',
      '#steps' => $steps,
    ];
  }
public function build ( ) { $ route_name = $ this -> routeMatch -> getRouteName ( ) ; if ( $ route_name !== 'acm_checkout.form' ) { return [ ] ; } // Load the CheckoutFlow plugin. $ config = \ Drupal :: config ( 'acm_checkout.settings' ) ; $ checkout_flow_plugin = $ config -> get ( 'checkout_flow_plugin' ) ? : 'multistep_default' ; $ plugin_manager = \ Drupal :: service ( 'plugin.manager.acm_checkout_flow' ) ; $ checkout_flow = $ plugin_manager -> createInstance ( $ checkout_flow_plugin , [ ] ) ; // Build the steps sent to the template. $ steps = [ ] ; $ visible_steps = array_filter ( $ checkout_flow -> getVisibleSteps ( ) , function ( $ step_definition ) { return ( ! isset ( $ step_definition [ 'hide_from_progress' ] ) ) ; } ) ; $ visible_step_ids = array_keys ( $ visible_steps ) ; $ current_step_id = $ checkout_flow -> getStepId ( ) ; $ current_step_index = array_search ( $ current_step_id , $ visible_step_ids ) ; // Get last step completed in the cart. $ cart = $ this -> cartStorage ; $ cart_step_id = $ cart -> getCheckoutStep ( ) ; $ cart_step_index = array_search ( $ cart_step_id , $ visible_step_ids ) ; $ index = 0 ; foreach ( $ visible_steps as $ step_id => $ step_definition ) { $ is_link = FALSE ; $ completed = FALSE ; if ( $ index < $ current_step_index ) { $ position = 'previous' ; } elseif ( $ index == $ current_step_index ) { $ position = 'current' ; } else { $ position = 'next' ; } $ label = $ step_definition [ 'label' ] ; // Add a class if this step has been completed already. if ( $ index < $ cart_step_index ) { $ completed = TRUE ; } // Set the label to a link if this step has already been completed so that // the progress bar can be used as a sort of navigation. if ( $ index <= $ cart_step_index && $ index !== $ current_step_index ) { $ is_link = TRUE ; $ label = Link :: createFromRoute ( $ label , 'acm_checkout.form' , [ 'step' => $ step_id , ] ) -> toString ( ) ; } $ steps [ ] = [ 'id' => $ step_id , 'label' => $ label , 'position' => $ position , 'completed' => $ completed , 'is_link' => $ is_link , ] ; $ index ++ ; } return [ '#attached' => [ 'library' => [ 'acm_checkout/checkout_progress' ] , ] , '#theme' => 'acm_checkout_progress' , '#steps' => $ steps , ] ; }
Builds the checkout progress block.

@return array
A render array.
Builds the checkout progress block .