I have view that uses url args: parent term id and term id/ids, so the url structure is like page/%/%
Title pattern for this view is: %1(%2)
However I have few pages with multi tids as second argument, so generated title is strange (very long). I am trying to change this title programmatically:
function bip_title_alter_views_post_render(&$view, &$output, &$cache) {
if ($view->name == 'kategorie_artykulow' && $view->current_display == 'page_9')
{
$args = explode(' ', $view->args[1]);
if (sizeof($args) < 2) {
return;
}
$title_pattern = 'Archiwum Oświadczeń Majątkowych w %dr.';
$term = taxonomy_term_load($args[0]);
if (! $term) {
return;
}
$title = sprintf($title_pattern, $term->name);
drupal_set_title($title);
}
}
function bip_title_alter_module_implements_alter(&$implementations, $hook) {
if ($hook == 'views_post_render') {
$group = $implementations['bip_title_alter'];
unset($implementations['bip_title_alter']);
$implementations['bip_title_alter'] = $group;
}
}
but title remains the same, I am sure that I am altering proper view.
Adding another display to view is not good option for me, because I have a lot existing urls and if I create another display with the same url structure and different args config always first display is handling request.
edit
I changed my custom module weight in system table to 9999 and I still see that title is altered after my module hook :/ It's so annoying
drupal_set_title()
early enough, then presumably something's overriding the title you've set. You could try printing out a backtrace from withindrupal_set_title()
and also print out the title passed in. This might show what's causing problems.