I'm not sure this is the right approach, but ...
I want to add a pager embedded in a node view, well, in a block above it anyway.
So that when viewing an individual item [/node/77], you can also go up to the index of all such items, adding the view as a context.
--------------------------
A B C ...
--------------------------
[Single node title]
Full node view
....
--------------------------

I've found how to retrieve the pager display for this view, (rough code below) and embedded it in the page, but the URLs it produce are linked back to the current page (/node/77?apage=B) etc which doesn't really work.

I found the point that this appears to be changeable (cool!)

function theme_alpha_pager($items, $current = '', $path = '', $query = '') {
...

so in views_alpha_pager_views_query_alter() I went:
From

  $view->alpha_pager_output = theme('alpha_pager', $items, $apage);

To

  $view->alpha_pager_output = theme('alpha_pager', $items, $apage, $view->url);

Is this correct? It works, but I'm not sure if there may have been a reason to have NOT passed it through in the first place. Will it break other stuff, or was it just left out?

My current block code, for reference is

$view = views_get_view('advertisers_index');
// Initialize the view - this prepares the pager for display
$args = array(); // the letter goes here?
$output = views_build_view('page',$view,$args);

// should find an easier way 
// - this is creating the entire view when all we want is the pager

print $view->alpha_pager_output;

Still under development...

In the long run, what would anyone suggest be the minimal code required to get this effect? I'm tracing the code through OK, but I'm not sure how much I can short-circuit the process. I'm hoping the caching means it's not really a problem.

CommentFileSizeAuthor
#6 140984_0.patch2.3 KBdouggreen
#1 140984.patch1.24 KBdouggreen

Comments

douggreen’s picture

StatusFileSize
new1.24 KB

I think you're onto something. Moving this code from the theme function to the invoking function makes sense. I also think that moving it would be more efficient (although this isn't that heavily used of an area).

I'm not sure if $view->url is always going to work or if we should stick with $_GET['q']. Did you try $_GET['q'] and it didn't work for you?

Does the attached patch help with what you're trying to do?

dman’s picture

Hm, no.
The $_GET default is precisely the problem.

You see, I'm ON page /node/77 but showing the pager.
So I was getting /node/77?apage=B which didn't work.

Instead I want the pager links to actually go back to the views working URL. So I used the available $view->url to get /advertiser-index?apage=B which was great.

I have a feeling that approach is incomplete, but I'm not sure haw many other contexts a view may be invoked from or embedded in. Such as a view without a 'page'. Where does it get used then? And will this break that?

douggreen’s picture

So what you're really asking for, is that $view to be added as an argument to theme_alpha_pager and theme_alpha_pager_link?

dman’s picture

No I ... Hm, maybe so.
Want I want is to be able to display the pager on pages other than the view itself.

The only way I've seen so far is to get views_alpha_pager_views_query_alter() to build the entire view, then extract get the bit I want, which was created more or less as a side effect of that.
If the prepare_alpha_pager($view) process (retrieving the letter items) or something was abstracted into a func of its own, it may make more sense to me.

My attempt at a fix was to make the alpha pager links always link to the owning view->url (instead of inheiriting the current context .. which would usually be the view->url anyway)
Are there actually any cases where it would be wrong to link the [A B C] links to the appropriate view->url ? If not, why leave it being defined by the $_GET?

.dan.

douggreen’s picture

OK, I think I understand now. The only solution that comes to mind is to set another variable in the $view and then modify the views_alpha_pager to look for this as an overide to $_GET['q'].

In your code:

  if (module_exists('views')) { // probably not required, but just in-case the views module is disabled
    $view = views_get_view('AlphaPager_Test');
    $view->alpha_pager_link = array('href' => $view->url);
    views_build_view('page', $view, array());
    print $view->alpha_pager_output;  
  }

I've attached a patch that would use this... Please check-out the latest 5.x-dev if you're going to apply the patch, because there have been a couple changes.

douggreen’s picture

StatusFileSize
new2.3 KB

Oops... I hit submit too quickly... here's my patch.

This seems like a bit of a hack for a very special case, but it makes it more extensible, and I don't think it has a negative impact on all other views ... other than an extra check for isset().

douggreen’s picture

Status: Active » Fixed

I committed this patch.

Anonymous’s picture

Status: Fixed » Closed (fixed)