Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
When clicking to sort on an ajax enabled Views table and on a column that has "Enable click sort: Sort Numerically" selected, I get the following error.
An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /views/ajax
StatusText: OK
ResponseText:
( ! ) Fatal error: Function name must be a string in /home/ubuntu/workspace/sandbox/sites/all/modules/views_php/plugins/views/views_php_handler_field.inc on line 185
Call Stack
#TimeMemoryFunctionLocation
10.0002752424{main}( )../index.php:0
20.509853025928menu_execute_active_handler( )../index.php:21
30.510653163792call_user_func_array
( )../menu.inc:503
40.510653164160views_ajax( )../menu.inc:0
50.594264902000view->preview( )../ajax.inc:71
60.644270358168views_plugin_display->preview( )../view.inc:1155
70.644270358248view->render( )../views_plugin_display.inc:2559
80.644270358328view->execute( )../view.inc:1011
90.699174599344views_php_plugin_query->execute( )../view.inc:991
100.699374635480views_plugin_query_default->execute( )../views_php_plugin_query.inc:17
110.702174780296views_php_plugin_pager->post_execute( )../views_plugin_query_default.inc:1373
120.710774792720views_php_handler_field->php_post_execute( )../views_php_plugin_pager.inc:35
130.713874810960usort
( )../views_php_handler_field.inc:162
140.713874811184views_php_handler_field->php_click_sort( )../views_php_handler_field.inc:0
Comments
Comment #1
chrisrikli CreditAttribution: chrisrikli commentedThere are a few problems within the php_click_sort function:
1) The arguments, which are to be rows with data, do not contain fields, just contain the entity type definitions. See this dpm of the object I'm try to sort:
2) The $function variable called on line 185 is an array, the second element of which is the click sort function name (in my case and yours "php_click_sort_numeric"). I can solve this issue by doing an ugly little hack to test the $function var to see if it's a string and if not populate $function with the value of the second element, but it's all moot because the incoming objects have no values. I believe this is related to this issue: http://drupal.org/node/1140896
Comment #2
modstore CreditAttribution: modstore commentedI had the same problem, alpha sort works, but not numeric. Something wrong in the code for this.
I got numeric sort working just using a custom sort snippet though.
Here's how to do it:
Ensure the 'Value Code' field returns the correct value, eg in my case: return $row->tid; - this is what the sort works on.
Set the output in 'Output Code' eg
print $row->php;
- if there is no value in your output, then it means your value code isn't correct.Set the click sorting to 'Sort using custom PHP code' and do the sort like this: return $row1->php - $row2->php;
Click sorting should now work.
Comment #3
arski CreditAttribution: arski commentedthanks for the working snippet, had the same issue.
Comment #4
Marko B CreditAttribution: Marko B commentedProblem I am having is when ucing VALUE CODE field there is very limited data. Just title, and Node ID and for body I also get node ID. Not full node is loaded. So I have to either load a full node, or use in output code already loaded node, right?
Comment #5
petrovichby CreditAttribution: petrovichby commentedThank you modstore, works for me.
Comment #6
TechNikh CreditAttribution: TechNikh commentedcustom sort code that worked for me
Comment #7
JordanMagnuson CreditAttribution: JordanMagnuson commentedWould be nice to get this fixed in the module.
Not sure of the solution yet, but the problem has something to do with the numeric sort being set as an array (rather than a string like the other sort functions) in views_php_handler_field.inc line 157:
This creates a problem around line 190: