You are here

function advanced_forum_forum_topic_list_sort_form in Advanced Forum 7.2

Same name and namespace in other branches
  1. 6.2 advanced_forum.module \advanced_forum_forum_topic_list_sort_form()

Sort form.

1 string reference to 'advanced_forum_forum_topic_list_sort_form'
advanced_forum_forum_topic_list_sort in ./advanced_forum.module
Display the "sort" widget.

File

./advanced_forum.module, line 672
Enables the look and feel of other popular forum software.

Code

function advanced_forum_forum_topic_list_sort_form($form_state) {
  $view = views_get_view('advanced_forum_topic_list');
  $view
    ->set_display('default');
  $view
    ->init_handlers();
  $view
    ->init_style();

  // Work up a list of possible fields.
  $handler =& $view->style_plugin;
  $fields =& $view->field;
  $columns = $handler
    ->sanitize_columns($handler->options['columns'], $fields);
  $options = array();
  foreach ($columns as $field => $column) {
    if ($field == $column && empty($fields[$field]->options['exclude'])) {
      if (empty($handler->options['info'][$field]['sortable']) || !$fields[$field]
        ->click_sortable()) {
        continue;
      }
      $label = check_plain(!empty($fields[$field]) ? $fields[$field]
        ->label() : '');
      $options[$field] = $label;
    }
  }
  $form['inline'] = array(
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
  );
  $form['inline']['order'] = array(
    '#type' => 'select',
    '#title' => t('Order by'),
    '#title_display' => 'invisible',
    '#options' => $options,
    '#default_value' => $handler->options['default'],
  );
  $form['inline']['sort'] = array(
    '#type' => 'select',
    '#title' => t('Sort'),
    '#title_display' => 'invisible',
    '#options' => array(
      'asc' => t('Up'),
      'desc' => t('Down'),
    ),
    '#default_value' => 'desc',
  );
  $form['inline']['submit'] = array(
    '#id' => 'sort-topic-submit',
    '#name' => '',
    '#type' => 'submit',
    '#value' => t('Sort'),
  );
  if (isset($_GET['page'])) {
    $form['page'] = array(
      '#type' => 'hidden',
      '#default_value' => $_GET['page'],
    );
  }
  if (!variable_get('clean_url', FALSE)) {
    $form['q'] = array(
      '#type' => 'hidden',
      '#value' => $_GET['q'],
    );
  }
  $view
    ->destroy();
  return $form;
}