How can I accurately determine when a customer is on the "Review" step in Commerce? I've created a custom checkout pane by extending Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase and added it to the "Order information" step in a checkout flow.  This accepts customer data.

The customer then progresses to the "Review" stage to confirm everything is correct. The customer can "Edit" their information if required, going back to the "Order information" step.

Within the custom pane I'm wanting to determine whether it's being displayed in the "Order information" step or the "Review" step.

getStepId() always returns what's in the config for the pane. In this case, "Order information".

$this->order->checkout_step seems to always return "Review", or maybe it's just reporting the highest step reached in the order thus far.

Is there a Commerce native way of determining the exact step being viewed? Or will I need to check the URL directly?

Edit: I've tried checking the route name, but both /checkout/[id]/order_information and /checkout/[id]/review return commerce_checkout.form.
A good place to look for example code related to the checkout form is CheckoutController.php. Its formPage() function ensures the form for the correct checkout page is built by comparing the checkout step requested in the URL to the checkout step the order last advanced to, ensuring the customer isn't trying to directly navigate to a later step than it's entitled to.

You can see that it uses the a route matcher to get the named 'step' parameter from the URL, and you can do the same thing in your own code. Typically you'd inject the route matcher into the checkout pane class, but a quick and dirty solution to fetch the current route matcher from the container is:

$container = \Drupal::getContainer();
$route_matcher = $container-&gt;get('current_route_match');
$step_id = $route_matcher-&gt;getParameter('step');


This will functionally do what you've done by looking at the URL directly, to be honest, but it's a bit more structured way of doing so.