protected function WizardPluginBase::buildSorts in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php \Drupal\views\Plugin\views\wizard\WizardPluginBase::buildSorts()
- 9 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 651
Class
- WizardPluginBase
- Base class for Views wizard plugins.
Namespace
Drupal\views\Plugin\views\wizardCode
protected function buildSorts(&$form, FormStateInterface $form_state) {
$sorts = [
'none' => $this
->t('Unsorted'),
];
// Check if we are allowed to sort by creation date.
$created_column = $this
->getCreatedColumn();
if ($created_column) {
$sorts += [
$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'] = [
'#type' => 'select',
'#title' => $this
->t('sorted by'),
'#options' => $sorts,
'#default_value' => isset($created_column) ? $created_column . ':DESC' : 'none',
];
}
}