You are here

function commerce_order_form_commerce_customer_customer_profile_form_alter in Commerce Core 7

Implements hook_form_FORM_ID_alter().

When a profile is being edited via its standalone form, display a message that tells the user the profile is going to be cloned if it already being referenced by a non-cart order.

File

modules/order/commerce_order.module, line 588
Defines the core Commerce order entity and API functions to manage orders and interact with them.

Code

function commerce_order_form_commerce_customer_customer_profile_form_alter(&$form, &$form_state) {
  if (!empty($form_state['customer_profile']->profile_id) && !commerce_order_commerce_customer_profile_can_delete($form_state['customer_profile'])) {
    $form['clone_message'] = array(
      '#markup' => '<div class="messages status">' . t('Because this profile is currently referenced by an order, if you change any field values it will save as a clone of the current profile instead of updating this profile itself. This is to maintain the integrity of customer data as entered on the order(s).') . '</div>',
      '#weight' => -100,
    );

    // Add the original profile ID to the form state so our custom submit handler
    // can display a message when the clone is saved.
    $form_state['original_profile_id'] = $form_state['customer_profile']->profile_id;
    $form['actions']['submit']['#submit'][] = 'commerce_order_customer_profile_form_submit';
  }
}