Closed (fixed)
Project:
Views (for Drupal 7)
Version:
4.7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
12 Oct 2006 at 13:18 UTC
Updated:
23 Dec 2006 at 01:46 UTC
I have written an alpha pager for views that I plan on submitting as a new module.
The best way to accomplish this is to add a pre_query hook that gets called in views_query_view. Since there is already a pre_view and post_query hook, I hope that this new hooks will be implemented. Summary of changes below. Full diff attached.
function views_build_view($type, &$view, $args = array(), $use_pager = false, $limit = 0, $page = 0) {
+ // Call a hook that'll let modules modify the view query before it is created
+ foreach (module_implements('views_pre_query') as $module) {
+ $function = $module .'_views_pre_query';
+ $output .= $function($view);
+ }
...
}
I was still able to hook into the views page display without the above change using the hack below. I'm hoping for a cleaner solution.
/**
* These functions are only used if the pre-query hook does not exist
*/
function _views_alpha_pager_init_callback() {
// NOTE: This is a hack!
// replace the views_view_page hook with our hook
// we'll call the views_view_page if we're not using the alpha pager
// make sure that the menu is built
/* $menu = */ menu_get_menu();
// but use a reference to the real menu so we can modify it
global $_menu;
foreach ($_menu['callbacks'] as &$menu) {
if ($menu['callback'] == 'views_view_page') {
$menu['callback'] = 'views_alpha_pager_page';
$update_cache = true;
}
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| views.module_1.diff | 654 bytes | douggreen |
Comments
Comment #1
douggreen commentedSee also http://drupal.org/project/views_alpha_pager
Comment #2
merlinofchaos commentedQuestion: Does the hook_views_query_alter not already supply what you need? It may not but you didn't mention it so I'm not entirely sure if you considered it.
Comment #3
douggreen commentedI tried to use hook_views_query_alter, but it is only called when _views_build_query() is called, and _views_build_query() is not called when the query is retrieved from the database. Specifically, when the condition on line 620 of views.module processes lands in the 'then' branch rather than the 'else', the hook_views_query_alter is not invoked. I need a hook that gets called every time the page is displayed and before the query is executed.
If there's a way to do it, please point me in the right direction and I'll look deeper. But I have yet to get a views_alpha_pager_views_query_alter to be invoked on my test view. I've uninstalled and reinstalled the module and dumped the cache.
Comment #4
merlinofchaos commentedHeh this went in in Views 1.1 and I never marked this fixed.
Comment #5
(not verified) commented