I'm working on manipulating the buttons used for the checkout flow of using D8 Commerce 2.
I'm using MYMODULE_form_commerce_checkout_flow_multistep_default_alter but its changing both the form buttons on the order information page and the review page.
I want to have different buttons on these two pages.
Is there a way when using a hook to manipulate a form to set it so its page specific?

  • I'm not sure if this qualifies as an answer or is a work around but I got what I wanted via matchpath and some good old fashion conditionals: ` $current_path = \Drupal::service('path.current')->getPath(); $patterns = "/checkout/*/order_information"; $match = \Drupal::service('path.matcher')->matchPath($current_path, $patterns); if ($match) { $form['actions']['next']['#attributes']['value'] = array('Continue'); $form['actions']['next']['#suffix'] = '<a href="/cart">Cancel</a>'; }` Commented Jul 5, 2019 at 3:00

1 Answer 1


Conditionals are still the answer, but turns out there's an easier way that doesn't involve getting the current path:

function MYMODULE_form_commerce_checkout_flow_multistep_default_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if ($form['#step_id'] == 'order_information') {
    Do stuff to the order information page form.
  if ($form['#step_id'] == 'review') {
    Do stuff to the review page form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.