Community

Proper Use of Views hook_views_pre_render() / Module Load Order

I'm having trouble implementing the hook_views_pre_render() for Views and I think it may be an issue regarding the order that module load. I have a custom module that already has working code, and I add to it this code:

function callboard_views_pre_render(&$view) {
  if ($view->name == 'drivers_availability_list') {
    echo 'test';
    // Code to change sort criteria here
  }
}

My goal is to create a condition for which a different sort order might be applied to this particular View. In testing I can't seem to get the page to View to pick up on this bit of code. Any ideas?

Comments

Using 'echo' is generally not

Using 'echo' is generally not the best approach. Given the way Drupal outputs the page I find they either interfere or are lost. You can use drupal_set_message() to place a message in the header region.

Correct Method to Test a Function?

I see, I can get by without echos, but when I try to just test to see if this hook is working:

function callboard_views_pre_render(&$view) {
drupal_set_message(t('This Code Is Working'), 'status');
}

I get nothing. Is this the right way to go about test to see if this bit of code is working? Hopefully I am heading in the right direction with this hook.

Two thoughts Your module is

Two thoughts

Your module is called 'callboard', correct?

Have you implemented hook_views_api()?

If not you need at least

function callboard_views_api() {
  return array(
    'api' => 3.0,
  );
}

Thats It!

I guess since I hadn't had to do that before on any other functions I used for menu and form altering that I just didn't think of it. Thanks so much!

EDIT: Strangely enough though implementing shuffle($view->result); on the view shuffles the second third and fourth columns, but leaves the first column (Name of Contact) unshuffled. It looks like that column is sorted by ascending ID.