diff --git a/modules/customer/commerce_customer.api.php b/modules/customer/commerce_customer.api.php index 99f33d9..0a27818 100644 --- a/modules/customer/commerce_customer.api.php +++ b/modules/customer/commerce_customer.api.php @@ -124,3 +124,22 @@ function hook_commerce_customer_profile_presave($profile) { function hook_commerce_customer_profile_can_delete($profile) { // No example. } + +/** + * Allows modules to alter the AJAX commands when copying customer profiles. + * + * During checkout the customer selects "My [x_profile] information is the same as + * my [y_profile] information." An AJAX callback is triggered. By altering the + * array of AJAX commands, a module can add additional commands to the response. + * + * @param array $commands + * An array of AJAX commands. + * @param type $form + * Nested array of form elements that comprise the form. + * @param type $form_state + * A keyed array containing the current state of the form. + */ +function hook_commerce_customer_profile_copy_callback_alter(&$commands, $form, $form_state) { + // Example. + $commands[] = ajax_command_alert('It works!'); +} diff --git a/modules/customer/includes/commerce_customer.checkout_pane.inc b/modules/customer/includes/commerce_customer.checkout_pane.inc index eebdcc0..9de0483 100644 --- a/modules/customer/includes/commerce_customer.checkout_pane.inc +++ b/modules/customer/includes/commerce_customer.checkout_pane.inc @@ -183,7 +183,15 @@ function commerce_customer_profile_pane_checkout_form($form, &$form_state, $chec */ function commerce_customer_profile_copy_ajax_callback($form, &$form_state) { $pane_id = reset($form_state['triggering_element']['#parents']); - return $form[$pane_id]; + + // Add replace element as default AJAX command. + $commands = array(); + $commands[] = ajax_command_replace(NULL, drupal_render($form[$pane_id])); + + // Allow other modules to add arbitrary AJAX commands on the refresh. + drupal_alter('commerce_customer_profile_copy_callback', $commands, $form, $form_state); + + return array('#type' => 'ajax', '#commands' => $commands); } /**