You are here

function ctools_export_ui::list_page in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 plugins/export_ui/ctools_export_ui.class.php \ctools_export_ui::list_page()

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.

1 call to ctools_export_ui::list_page()
ctools_export_ui::set_item_state in plugins/export_ui/ctools_export_ui.class.php
Set an item's state to enabled or disabled and output to user.

File

plugins/export_ui/ctools_export_ui.class.php, line 155

Class

ctools_export_ui
Base class for export UI.

Code

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) {
      return 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']);
  }

  // We rely on list_form_submit() to build the table rows. Clean out any
  // AJAX markers that would prevent list_form() from automatically
  // submitting the form.
  if ($js) {
    unset($input['js'], $input['ctools_ajax']);
  }

  // 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,
  );
  $help_area = $this
    ->help_area($form_state);
  ctools_include('form');
  $form = ctools_build_form('ctools_export_ui_list_form', $form_state);
  $output = $this
    ->list_header($form_state) . $this
    ->list_render($form_state) . $this
    ->list_footer($form_state);
  if (!$js) {
    $this
      ->list_css();
    return $help_area . $form . $output;
  }
  ctools_include('ajax');
  $commands = array();
  $commands[] = ctools_ajax_command_replace('#ctools-export-ui-list-items', $output);
  if (!empty($replace_form)) {
    $commands[] = ctools_ajax_command_replace('#ctools-export-ui-list-form', $form);
  }
  ctools_ajax_render($commands);
}