Commit 8c60e640 authored by generalredneck's avatar generalredneck

[#1614234] Adding the new sort hander and making it work for node title.

parent d1dd13bb
<?php
class views_natural_sort_handler_sort extends views_handler_sort {
/**
* Provide a list of options for the default sort form.
* Should be overridden by classes that don't override sort_form
*/
function sort_options() {
return array(
'ASC' => t('Sort ascending'),
'DESC' => t('Sort descending'),
'NASC' => t('Sort ascending naturally'),
'NDESC' => t('Sort descending naturally'),
);
}
function query() {
switch ($this->options['order']) {
case 'NASC':
case 'NDESC':
$order = substr($this->options['order'], 1);
$vns_alias = $this->query->ensure_table('views_natural_sort');
$this->query->add_orderby($vns_alias, 'content', $order);
break;
default:
parent::query();
}
}
}
......@@ -3,3 +3,6 @@ description = Sort results naturaly on a text field skipping articles like "the"
dependencies[] = views
package = Views
core = 7.x
; Views handlers
files[] = handlers/views_natural_sort_handler_sort.inc
......@@ -15,34 +15,20 @@ function views_natural_sort_views_data() {
$data['views_natural_sort']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
// We only support sorting on title so go ahead and build filter it into the join.
'field' => 'eid',
'extra' => array(
array(
'field' => 'field',
'value' => 'title',
'operator' => '=',
'field' => 'entity_type',
'value' => 'node',
)
)
),
);
return $data;
}
$data['views_natural_sort']['content'] = array(
'title' => 'Title - Natural',
'group' => t('Node'),
'help' => t('The title of a node filtered for natural sorting.'),
// Normally you wouldn't want a field or argument on this but its available for grouping.
'field' => array(
'handler' => 'views_handler_field_node',
'click sortable' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
function views_natural_sort_views_data_alter(&$data) {
return $data;
// TODO: Add a field and argument handler to support grouping.
$data['node']['title']['sort']['handler'] = 'views_natural_sort_handler_sort';
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment