Comments

Wolf_22’s picture

Issue summary: View changes

Update: I've managed to find a way to override the Pager IDs by using the following code in my custom module (not in template.php):

function mymodulename_views_pre_view(&$view){
    if($view->name == 'myviewname' && $view->current_display == 'block'){
        $pager_options = $view->display_handler->get_option('pager');
	$view->display['default']->handler->options['pager']['options']['id'] = pager_id_generator();
	$view->display_handler->set_option('pager', $pager_options);
    }
}

function pager_id_generator(){
    static $pager_id;
    if(!isset($pager_id)){
	$pager_id = 2; //Not sure if this is necessary but I included it anyway (saw it in some example code)...
    }else{
        $pager_id++;
    }
    return $pager_id;
}

(At least, I believe this is overriding the IDs because it seemed to be in the var_dump / print_r information I wrote to a file.)

That aside, I'm still having problems with the pager's "Next" button and after doing more testing, it seems as if it might be due to ampersands.

Here's what I'm doing in detail:

  1. I run some SQL to return an array of field values associated with user profiles. (In my case, it's an array of departments.)
  2. I use a FOR loop to iterate through the above array to print these off as headings for a staff listing page.
  3. In the above FOR routine during each iteration, I embed the block view and pass in the department heading value to be used as a contextual filter.
  4. When I view the page, everything looks great.
  5. For departments that have ampersands in their department, clicking the "Next" button in the pager makes the view--minus the exposed filter--completely disappear for that respective view instance.

Here's a basic rundown of what I'm using in all this:

function mymodulename_preprocess_page(&$vars){
$bundle	   = get_bundle_type($vars);
$page_alias   = drupal_get_path_alias('node/'.arg(1));

if($bundle === 'standard_page' && $page_alias === 'myalias'){
    $departments	= flatten(db_query("SELECT DISTINCT field_department_value FROM {field_data_field_department} WHERE field_department_value IS NOT NULL ORDER BY field_department_value ASC")->fetchAll(PDO::FETCH_ASSOC));

    $vars['page']['content']['system_main']['nodes'][arg(1)]['body'][0]['#markup'] = '<div id="bottom"><form id="live-search" action="" class="styled" method="post"><label>Department Contacts</label><input type="text" class="text-input" id="filter" value="" /><span id="filter-count"></span></form>';

    $vars['page']['content']['system_main']['nodes'][arg(1)]['body'][0]['#markup'] .= '<div id="other_pager">';

    for($i=0;$i<count($departments);$i++){
        $vars['page']['content']['system_main']['nodes'][arg(1)]['body'][0]['#markup'] .= '<div class="dept"><a href="#" title="'.$departments[$i].'">'.ucwords(strtolower($departments[$i])).'</a><div>'.views_embed_view('myviewname', 'block', $departments[$i]).'</div></div>';
    }
    
    $vars['page']['content']['system_main']['nodes'][arg(1)]['body'][0]['#markup'] .= '</div>';
}

As you can see from the above code, I assign $departments the results from the query that I use to extract and flatten to a 1 dimensional array of department identifiers (i.e. - "Sales & Marketing," "Human Resources," etc.). These values come from a field found in users' profiles.

After I do this, I then iterate through each of these and print out both the heading and the block view whereby I use the department heading value as a parameter for the view that's embedded directly underneath the headings.

Everything works great except the view instances that correspond to departments that have an ampersand in them. Granted, this is somewhat an assumption that it's causing the pager issues, but it seems pretty sound given that all of the instances corresponding to those departments seem to have this pager problem.

Thoughts? Does anyone know how to go about fixing this?

lazyD’s picture

Above views_pre_view code is not working for me
my Views version 7.x.3.14

MustangGB’s picture

Status: Active » Closed (outdated)

Closing this as outdated to tidy up a bit around here. If you're still having problems with the latest release please create a new issue.