Allow altering individual pane forms without having to alter the entire checkout form

Created on 5 March 2021, over 4 years ago
Updated 31 January 2023, over 2 years ago

Describe your bug or feature request.

If you want to alter the form of a checkout pane, you must implement a form alter for the entire checkout form and check if your pane exists. This is a bit messy. Normally I would just swap a checkout pane plugin's class and be done with it. But this might be a good developer experience additional.

Proposal:

Inject the module_handler service into CheckoutFlowWithPanesBase class and invoke an alter called checkout_pane_form and checkout_pane_PANE_ID_form. The checkout flow is passed as context.

In \Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowWithPanesBase::buildForm:

      $form[$pane_id] = $pane->buildPaneForm($form[$pane_id], $form_state, $form);
      \Drupal::moduleHandler()->alter([
        'commerce_checkout_pane_form',
        "commerce_checkout_pane_{$pane_id}_form",
      ], $form[$pane_id], $this);

Add commerce_checkout.api.php to document the hook.

hook_commerce_checkout_pane_form_alter(array &$pane_form, CheckoutFlowWithPanesInterface $checkout);
hook_commerce_checkout_pane_PANE_ID_form_alter(array &$pane_form, CheckoutFlowWithPanesInterface $checkout);

✨ Feature request
Status

Needs work

Version

2.0

Component

Checkout

Created by

πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024