You are here

function commerce_payment_form_commerce_order_ui_order_delete_form_alter in Commerce Core 7

Implements hook_form_FORM_ID_alter().

Makes sure the user deleting an order has permissions to delete associated payment transactions if they exist on the order being deleted. Prevents deletion of the order if the user does not have access.

File

modules/payment/commerce_payment.module, line 1214
Defines the payment system and checkout integration.

Code

function commerce_payment_form_commerce_order_ui_order_delete_form_alter(&$form, &$form_state) {
  if (commerce_payment_order_has_payments($form_state['order'])) {
    if (user_access('administer payments')) {

      // Add a required checkbox to force user to confirm
      // deletion of attached payments as well.
      $form['delete_order_payments'] = array(
        '#type' => 'checkbox',
        '#title' => t('Confirm deletion of order and all of its related payment transactions.'),
        '#required' => TRUE,
      );
      $form['actions']['submit']['#states']['visible'][] = array(
        ':input[name="delete_order_payments"]' => array(
          'checked' => TRUE,
        ),
      );
    }
    else {

      // Inform the user they cannot delete the order due
      // to attached payments.
      $form['description']['#markup'] = '<p>' . t('This order has payment transactions attached to it. You do not have sufficient permissions to delete it.');
      $form['actions']['submit']['#access'] = FALSE;
    }
  }
}