Builds the form structure for selecting the view's sort order.
By default, this adds a "sorted by [date]" filter (when it is available).
protected function build_sorts(&$form, &$form_state) {
$sorts = array(
'none' => t('Unsorted'),
);
// Check if we are allowed to sort by creation date.
$created_column = $this
->getCreatedColumn();
if ($created_column) {
$sorts += array(
$created_column . ':DESC' => t('Newest first'),
$created_column . ':ASC' => t('Oldest first'),
);
}
if ($available_sorts = $this
->getAvailableSorts()) {
$sorts += $available_sorts;
}
foreach ($sorts as &$option) {
if (is_object($option)) {
$option = $option
->get();
}
}
// If there is no sorts option available continue.
if (!empty($sorts)) {
$form['displays']['show']['sort'] = array(
'#type' => 'select',
'#title' => t('sorted by'),
'#options' => $sorts,
'#default_value' => isset($created_column) ? $created_column . ':DESC' : 'none',
);
}
}