Drupal Commerce 2 - Modify Review Checkout Pane

217 Views Asked by At

I'm using guidance from https://docs.drupalcommerce.org/commerce2/developer-guide/checkout/replacing-existing-checkout-pane to try to modify the Review checkout pane.

I need to check some data from a custom checkout pane and, based on that logic, disable the 'Complete Payment' submit button and replace it with a warning.

Within my custom_module.module, I am using:

<?php

/**
 * Implements hook_commerce_checkout_pane_info_alter().
 */
function custom_module_check_commerce_checkout_pane_info_alter(&$definitions) {

  if (isset($definitions['review'])) {
    $definitions['review']['class'] = \Drupal\custom_module\Plugin\Commerce\CheckoutPane\Review::class;
    $definitions['review']['provider'] = 'custom_module';
  }
}

And within Review.php :

<?php

namespace Drupal\custom_module\Plugin\Commerce\CheckoutPane;

use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\Review as BaseReview;
use Drupal\Core\Form\FormStateInterface;

/**
 * Provides a custom payment information pane.
 */
class Review extends BaseReview {

  /**
   * {@inheritdoc}
   */
  public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
    $pane_form = parent::buildPaneForm($pane_form, $form_state, $complete_form);
    // Do something custom with the pane form here.
    $pane_form['test'] = [
        '#markup' => $this->t('Error.'),
      ];
    return $pane_form;
  }
}

This works fine, I get some markup with 'Error' above the 'Pay and Complete Purchase' button.

Now, how do I disable the button if required?

Help would be appreciated!

Thanks

0

There are 0 best solutions below