Custom Sort View Handler is Ignored

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by jeff00seattle on April 8, 2009 at 4:58pm

Hi

I have read the link http://drupal.org/node/357079 , but my custom sort handler is not getting called.

Implemented is the following empty sort handler. However, when I select the activated table-style column to sort, this sort handler is ignored.

<?php
class region_views_handler_sort extends views_handler_sort {
function
query() {
parent::query();
drupal_set_message('region_id custom query()');
}

function
options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);

drupal_set_message('region_id custom options_form()');
}
}
?>

There is also implemented a field handler applied to the same views data item (working):

<?php
class region_views_handler_field_url extends views_handler_field_url {
// check access if user has permissions to view region
function access() {
global
$user;
return
region_access('view', NULL, $user);
}

// render (numeric) region_id to become (string) region_name with link or not
function render($values) {
$region_id = $values->{$this->field_alias};
$region_assoc = region_fetch_array($region_id);

$region_name = $region_assoc['region_name'];
$region_nid = $region_assoc['region_nid'];

if (!empty(
$this->options['display_as_link'])) {
return
l(check_plain($region_name), "node/{$region_nid}", array('html' => TRUE));
}
else {
return
$region_name;
}
}
}
?>

Implemented data item within hook_views_data using both the (working) field and (ignored) sort handlers:

<?php
$data
['location']['region_id'] = array(
'title' => t('Region ID'),
'help' => t('Auto-Assigned ID from Region'),
'relationship' => array(
'base' => 'region',
'field' => 'region_id',
'handler' => 'views_handler_relationship',
'label' => t('Region'),
),
'field' => array(
'handler' => 'region_views_handler_field_url',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'region_views_handler_sort',
),
);
?>

Implemented is a hook_views_handlers that holds both handlers:

<?php
function location_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'location'),
),
'handlers' => array(
// field handlers
'region_views_handler_field_url' => array(
'parent' => 'views_handler_field_url',
),
'region_views_handler_sort' => array(
'parent' => 'views_handler_sort',
),
)
);
}
?>

Anybody have any ideas why this sort handler is ignored?

Jeff in Seattle

Comments

The tablesort uses the field

Posted by merlinofchaos on April 8, 2009 at 8:33pm

The tablesort uses the field to sort, not the sort handler. On your field, implement click_sort()

Implementing a custom click_sort()...

Posted by jeff00seattle on June 18, 2009 at 4:10pm

Hi Earl

A little more savvy about implementing custom views_handler_field(s) since I last wrote this topic submission, I am back again looking at click sorting columns.

Your response is that I should add a custom method click_sort().

So far, what I have seen for custom method click_sort() is that View sorts are SQL-based, because custom formulas are SQL-compatible snippets.

My custom views_handler_field renderings are not SQL-based; in other words, it takes the value returned by the field_alias and applies it to a PHP-Drupal-based function and returns it to be displayed.

Assuming that I need a custom method click_sort(), do you know of any good articles pertaining to implementing custom non-SQL-based sorting?

Thanks

Jeff in Seattle

Reference to earlier submission: http://groups.drupal.org/node/23369

Thanks

Jeff in Seattle

Custom click sort

Posted by msplash9 on April 7, 2016 at 5:05am

Hi Jeff,

Did you find a way to create custom clicksort ? If so can you please share it with me . I am also struck with the same problem

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /