You are here

protected function WizardPluginBase::buildSorts in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php \Drupal\views\Plugin\views\wizard\WizardPluginBase::buildSorts()

Builds the form structure for selecting the view's sort order.

By default, this adds a "sorted by [date]" filter (when it is available).

1 call to WizardPluginBase::buildSorts()
WizardPluginBase::buildForm in core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php
Form callback to build other elements in the "show" form.

File

core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php, line 620
Contains \Drupal\views\Plugin\views\wizard\WizardPluginBase.

Class

WizardPluginBase
Base class for Views wizard plugins.

Namespace

Drupal\views\Plugin\views\wizard

Code

protected function buildSorts(&$form, FormStateInterface $form_state) {
  $sorts = array(
    'none' => $this
      ->t('Unsorted'),
  );

  // Check if we are allowed to sort by creation date.
  $created_column = $this
    ->getCreatedColumn();
  if ($created_column) {
    $sorts += array(
      $created_column . ':DESC' => $this
        ->t('Newest first'),
      $created_column . ':ASC' => $this
        ->t('Oldest first'),
    );
  }
  if ($available_sorts = $this
    ->getAvailableSorts()) {
    $sorts += $available_sorts;
  }

  // If there is no sorts option available continue.
  if (!empty($sorts)) {
    $form['displays']['show']['sort'] = array(
      '#type' => 'select',
      '#title' => $this
        ->t('sorted by'),
      '#options' => $sorts,
      '#default_value' => isset($created_column) ? $created_column . ':DESC' : 'none',
    );
  }
}