/**
  * Create a command array to redraw a pane.
  */
 function command_update_pane($pid)
 {
     if (is_object($pid)) {
         $pane = $pid;
     } else {
         $pane = $this->display->content[$pid];
     }
     $this->commands[] = ajax_command_replace("#panels-ipe-paneid-{$pane->pid}", $this->render_pane($pane));
     $this->commands[] = ajax_command_changed("#panels-ipe-display-{$this->clean_key}");
 }
 /**
  * Create a command to update the links on a region after a change was made.
  */
 function command_update_region_links($id) {
   $this->commands[] = ajax_command_replace('.panels-region-links-' . $id, $this->get_region_links($id));
 }
 /**
  * AJAX Callback for the path table.
  *
  * @param $form
  * @param $form_state
  * @param $offset_to_root
  * @param $clear
  *
  * @throws \Exception
  * @return array
  */
 public static function ajaxCallbackBase($form, $form_state, $offset_to_root, $clear = false)
 {
     if (!array_key_exists('triggering_element', $form_state)) {
         throw new \Exception('The trigger could not be found.');
     }
     $trigger = $form_state['triggering_element'];
     $parents = array_slice($trigger['#array_parents'], 0, count($trigger['#array_parents']) - $offset_to_root);
     $parents[] = 'paths';
     $parents_form = drupal_array_get_nested_value($form, $parents);
     $commands = array();
     $commands[] = ajax_command_replace(null, theme('publisher_purge_configure_content_type_table', array('paths_form' => $parents_form)));
     $commands[] = ajax_command_prepend(null, theme('status_messages'));
     if ($clear) {
         // Get the "Add Path" textbox.
         $add_path_parents = array_slice($parents, 0, count($parents) - 1);
         $add_path_parents[] = 'add_path';
         $add_path_parents[] = 'path';
         $add_path = drupal_array_get_nested_value($form, $add_path_parents);
         // TODO: Actually find out why the form API is adding numbers to the IDs.
         $add_path_id = str_replace('--2', '', $add_path['#id']);
         $commands[] = ajax_command_invoke('#' . $add_path_id, 'val', array(''));
     }
     return array('#type' => 'ajax', '#commands' => $commands);
 }
 /**
  * Master entry point for handling a list.
  *
  * It is unlikely that a child object will need to override this method,
  * unless the listing mechanism is going to be highly specialized.
  */
 function list_page($js, $input)
 {
     $this->items = ctools_export_crud_load_all($this->plugin['schema'], $js);
     // Respond to a reset command by clearing session and doing a drupal goto
     // back to the base URL.
     if (isset($input['op']) && $input['op'] == t('Reset')) {
         unset($_SESSION['ctools_export_ui'][$this->plugin['name']]);
         if (!$js) {
             drupal_goto($_GET['q']);
         }
         // clear everything but form id, form build id and form token:
         $keys = array_keys($input);
         foreach ($keys as $id) {
             if (!in_array($id, array('form_id', 'form_build_id', 'form_token'))) {
                 unset($input[$id]);
             }
         }
         $replace_form = TRUE;
     }
     // If there is no input, check to see if we have stored input in the
     // session.
     if (!isset($input['form_id'])) {
         if (isset($_SESSION['ctools_export_ui'][$this->plugin['name']]) && is_array($_SESSION['ctools_export_ui'][$this->plugin['name']])) {
             $input = $_SESSION['ctools_export_ui'][$this->plugin['name']];
         }
     } else {
         $_SESSION['ctools_export_ui'][$this->plugin['name']] = $input;
         unset($_SESSION['ctools_export_ui'][$this->plugin['name']]['q']);
     }
     // This is where the form will put the output.
     $this->rows = array();
     $this->sorts = array();
     $form_state = array('plugin' => $this->plugin, 'input' => $input, 'rerender' => TRUE, 'no_redirect' => TRUE, 'object' => &$this);
     if (!isset($form_state['input']['form_id'])) {
         $form_state['input']['form_id'] = 'ctools_export_ui_list_form';
     }
     // If we do any form rendering, it's to completely replace a form on the
     // page, so don't let it force our ids to change.
     if ($js && isset($_POST['ajax_html_ids'])) {
         unset($_POST['ajax_html_ids']);
     }
     $form = drupal_build_form('ctools_export_ui_list_form', $form_state);
     $form = drupal_render($form);
     $output = $this->list_header($form_state) . $this->list_render($form_state) . $this->list_footer($form_state);
     if (!$js) {
         $this->list_css();
         return $form . $output;
     }
     $commands = array();
     $commands[] = ajax_command_replace('#ctools-export-ui-list-items', $output);
     if (!empty($replace_form)) {
         $commands[] = ajax_command_replace('#ctools-export-ui-list-form', $form);
     }
     print ajax_render($commands);
     ajax_footer();
 }
/**
 * hook_fasttoggle_ajax_alter
 *
 * Hook allowing callees to modify the ajax sent back to a browser after a link
 * is toggled.
 *
 * @param $ajax_commands
 *   The default ajax commands (arg to ajax_render).
 * @param $object_type
 *   The type of object being handled.
 * @param $object
 *   An instance of the object that has been modified, as saved.
 * @param $params
 *   An array of further parameters, since drupal_alter only supports 3
 *   parameters. The array contains the group, option and view strings
 *   that describe what option was toggled and what view (if any) was
 *   applied to the object in its original render.
 */
function fasttoggle_node_fasttoggle_ajax_alter(&$ajax_commands, $object_type, $object, $params)
{
    if ($object_type != "node") {
        return;
    }
    // Replace the original content with that the updated content, so far as we're able (we don't
    // get it exactly right yet).
    $unrendered = node_view($object, $params['view']);
    if ($object->comment > 0 && module_exists('comment') && $params['view'] == 'full') {
        $unrendered['comments'] = comment_node_page_additions($object);
    }
    $replacement_content = drupal_render($unrendered);
    $ajax_commands[] = ajax_command_replace('.' . 'node-content-' . $object->nid, $replacement_content);
}