You are here

function ctools_export_ui::list_form_submit 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_form_submit()

Submit the filter/sort form.

This submit handler is actually responsible for building up all of the rows that will later be rendered, since it is doing the filtering and sorting.

For the most part, you should not need to override this method, as the fiddly bits call through to other functions.

File

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

Class

ctools_export_ui
Base class for export UI.

Code

function list_form_submit(&$form, &$form_state) {

  // Filter and re-sort the pages.
  $plugin = $this->plugin;
  $schema = ctools_export_get_schema($this->plugin['schema']);
  $prefix = ctools_export_ui_plugin_base_path($plugin);
  foreach ($this->items as $name => $item) {

    // Call through to the filter and see if we're going to render this
    // row. If it returns TRUE, then this row is filtered out.
    if ($this
      ->list_filter($form_state, $item)) {
      continue;
    }

    // Note: Creating this list seems a little clumsy, but can't think of
    // better ways to do this.
    $allowed_operations = drupal_map_assoc(array_keys($plugin['allowed operations']));
    $not_allowed_operations = array(
      'import',
    );
    if ($item->{$schema['export']['export type string']} == t('Normal')) {
      $not_allowed_operations[] = 'revert';
    }
    elseif ($item->{$schema['export']['export type string']} == t('Overridden')) {
      $not_allowed_operations[] = 'delete';
    }
    else {
      $not_allowed_operations[] = 'revert';
      $not_allowed_operations[] = 'delete';
    }
    $not_allowed_operations[] = empty($item->disabled) ? 'enable' : 'disable';
    foreach ($not_allowed_operations as $op) {

      // Remove the operations that are not allowed for the specific
      // exportable.
      unset($allowed_operations[$op]);
    }
    $operations = array();
    foreach ($allowed_operations as $op) {
      $operations[$op] = array(
        'title' => $plugin['allowed operations'][$op]['title'],
        'href' => ctools_export_ui_plugin_menu_path($plugin, $op, $name),
      );
      if (!empty($plugin['allowed operations'][$op]['ajax'])) {
        $operations[$op]['attributes'] = array(
          'class' => 'ctools-use-ajax',
        );
      }
      if (!empty($plugin['allowed operations'][$op]['token'])) {
        $operations[$op]['query'] = array(
          'token' => drupal_get_token($op),
        );
      }
    }
    $this
      ->list_build_row($item, $form_state, $operations);
  }

  // Now actually sort
  if ($form_state['values']['sort'] == 'desc') {
    arsort($this->sorts);
  }
  else {
    asort($this->sorts);
  }

  // Nuke the original.
  $rows = $this->rows;
  $this->rows = array();

  // And restore.
  foreach ($this->sorts as $name => $title) {
    $this->rows[$name] = $rows[$name];
  }
}