public function Table::buildSortPost in Views Aggregator Plus 8
Records the "active" field, i.e. the column clicked to be sorted.
Also records the sort order ('asc' or 'desc'). This is identical to Table::buildSortPost, except for the last statement, which has a condition added.
Overrides Table::buildSortPost
File
- src/
Plugin/ views/ style/ Table.php, line 1307
Class
- Table
- Style plugin to render each item as a row in a table.
Namespace
Drupal\views_aggregator\Plugin\views\styleCode
public function buildSortPost() {
$query = $this->view
->getRequest()->query;
$order = $query
->get('order');
if (!isset($order)) {
// Check for a 'default' clicksort. If there isn't one, exit gracefully.
if (empty($this->options['default'])) {
return;
}
$sort = $this->options['default'];
if (!empty($this->options['info'][$sort]['default_sort_order'])) {
$this->order = $this->options['info'][$sort]['default_sort_order'];
}
else {
$this->order = !empty($this->options['order']) ? $this->options['order'] : 'asc';
}
}
else {
$sort = $order;
// Store the $order for later use.
$request_sort = $query
->get('sort');
$this->order = !empty($request_sort) ? strtolower($request_sort) : 'asc';
}
// If a sort we don't know anything about gets through, exit gracefully.
if (empty($this->view->field[$sort])) {
return;
}
// Ensure $this->order is valid.
if ($this->order != 'asc' && $this->order != 'desc') {
$this->order = 'asc';
}
// Store the $sort for later use.
$this->active = $sort;
// Tell the field to click-sort, but only if it is a standard Views field or
// a field not aggregated, in which cases sorting will be dealt with in
// $this->pre_render().
$plugin_id = $this->view->field[$sort]
->getPluginId();
if (!in_array($plugin_id, [
'addressfield',
'taxonomy_term_reference',
'custom',
'view',
'webform_submission_field_numeric',
'webform_submission_field',
]) && $this->options['info'][$sort]['has_aggr'] == 0) {
$this->view->field[$sort]
->clickSort($this->order);
}
}