/** * AJAX entry point to create the controller form for an IPE. */ function ajax_save_form($break = NULL) { if ($this->ipe_test_lock('save-form', $break)) { return; } // Reset the $_POST['ajax_html_ids'] values to preserve // proper IDs on form elements when they are rebuilt // by the Panels IPE without refreshing the page $_POST['ajax_html_ids'] = array(); $form_state = array('display' => &$this->display, 'content_types' => $this->cache->content_types, 'rerender' => FALSE, 'no_redirect' => TRUE, 'layout' => $this->plugins['layout']); $output = drupal_build_form('panels_ipe_edit_control_form', $form_state); if (empty($form_state['executed'])) { // At this point, we want to save the cache to ensure that we have a lock. $this->cache->ipe_locked = TRUE; panels_edit_cache_set($this->cache); $this->commands[] = array('command' => 'initIPE', 'key' => $this->clean_key, 'data' => drupal_render($output), 'lockPath' => $this->get_url('unlock_ipe')); return; } // Check to see if we have a lock that was broken. If so we need to // inform the user and abort. if (empty($this->cache->ipe_locked)) { $this->commands[] = ajax_command_alert(t('A lock you had has been externally broken, and all your changes have been reverted.')); $this->commands[] = array('command' => 'cancelIPE', 'key' => $this->clean_key); return; } // Otherwise it was submitted. if (!empty($form_state['clicked_button']['#save-display'])) { // Saved. Save the cache. panels_edit_cache_save($this->cache); // A rerender should fix IDs on added panes as well as ensure style changes are // rendered. $this->meta_location = 'inline'; $this->commands[] = ajax_command_replace("#panels-ipe-display-{$this->clean_key}", panels_render_display($this->display, $this)); } else { // Cancelled. Clear the cache. panels_edit_cache_clear($this->cache); } $this->commands[] = array('command' => 'endIPE', 'key' => $this->clean_key); }
/** * Allows modules to add arbitrary AJAX commands to the array returned from the * customer profile copy checkbox refresh. * * When a customer checks or unchecks a box to copy the relevant information * from one customer profile to another, the associated checkout pane gets an * AJAX refresh. The form will be rebuilt using the new form state and the AJAX * callback of the element that was clicked will be called. For this checkbox it * is commerce_customer_profile_copy_refresh(). * * Instead of just returning the checkout pane to be rendered, this AJAX refresh * function returns an array of AJAX commands that includes the necessary form * element replacement. However, other modules may want to interact with the * refreshed form. They can use this hook to add additional items to the * commands array, which is passed to the hook by reference. Note that the form * array and form state cannot be altered, just the array of commands. * * @param &$commands * The array of AJAX commands used to refresh the customer profile checkout * pane with updated form elements. * @param $form * The rebuilt form array. * @param $form_state * The form state array from the form. * * @see commerce_customer_profile_copy_refresh() */ function hook_commerce_customer_profile_copy_refresh_alter(&$commands, $form, $form_state) { // Display an alert message. $commands[] = ajax_command_alert(t('The customer profile checkout pane has been updated.')); }
/** * Allows modules to add arbitrary AJAX commands to the array returned from the * standard address field widget refresh. * * @param &$commands * The array of AJAX commands used to refresh the address field widget. * @param $form * The rebuilt form array. * @param $form_state * The form state array from the form. * * @see addressfield_standard_widget_refresh() */ function hook_addressfield_standard_widget_refresh_alter(&$commands, $form, $form_state) { // Display an alert message. $commands[] = ajax_command_alert(t('The address field widget has been updated.')); }
/** * Allows modules to add arbitrary AJAX commands to the array returned from the * Add to Cart form attributes refresh. * * When a product selection widget's value is changed, whether it is a product * select list or a product attribute field widget, the Add to Cart form gets * an AJAX refresh. The form will be rebuilt using the new form state and the * AJAX callback of the element that was changed will be called. For this form * it is commerce_cart_add_to_cart_form_attributes_refresh(). * * The cart form's particular AJAX refresh function returns an array of AJAX * commands that perform HTML replacement on the page. However, other modules * may want to interact with the refreshed form. They can use this hook to * add additional items to the commands array, which is passed to the hook by * reference. Note that the form array and form state cannot be altered, just * the array of commands. * * @param &$commands * The array of AJAX commands used to refresh the cart form with updated form * elements and to replace product fields rendered on the page to match the * currently selected product. * @param $form * The rebuilt form array. * @param $form_state * The form state array from the form. * * @see commerce_cart_add_to_cart_form_attributes_refresh() */ function hook_commerce_cart_attributes_refresh_alter(&$commands, $form, $form_state) { // Display an alert message showing the new default product ID. $commands[] = ajax_command_alert(t('Now defaulted to product @product_id.', array('@product_id' => $form['product_id']['#value']))); }
/** * Allows modules to alter the AJAX commands when selecting another customer * profile. * * During checkout the user selects the "address on file" from a dropdown list * of customer profiles. The response (prefilled fields) is handled using AJAX. * 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_addressbook_callback_alter(&$commands, $form, $form_state) { // Example. $commands[] = ajax_command_alert('It works!'); }
/** * Alter the commands, form and formstate at the point where the coupon module * is about return from its checkout pane ajax handler. * * @param array $commands * Any commands that have been set * * @param array $form * The checkout form * * @param array $form_state * The checkout form state */ function hook_commerce_coupon_add_coupon_ajax_alter($commands, &$form, &$form_state) { // Set a JS alert when the coupon checkout pane form is rebuilt via ajax. $commands[] = ajax_command_alert(t('Thank you for redeeming a coupon')); }