6

I have a view named "taxonomy_term_custom." The preprocess code below works to do some specific stuff for this view, but I would like to override the hook like this:

function mywebsite_glue_preprocess_views_view__taxonomy_term_custom(&$vars) {
}

Is this possible?

function mywebsite_glue_preprocess_views_view(&$vars) {
  if($vars['view']->name == 'taxonomy_term_custom'){
    dpm($vars);
    // do stuff
  }
}

3 Answers 3

5

In Drupal 7 this preprocess function will not automatically get picked up as it did in Drupal 6. There is a workaround posted here if you want the same behaviour as Drupal 6. For the issue.

1
  • Is it just hook_preprocess_views_view() that is affected? I've looked through the issue and can't find a definitive list of which hooks are affected. Jul 29, 2012 at 10:59
5

Just call preprocess for each view.

function mywebsite_glue_preprocess_views_view(&$vars) {
  $function_name = __FUNCTION__ . '__' . $vars['view']->name;
  if (function_exists($function_name)) {
    $function_name($vars);
  }
}

function mywebsite_glue_preprocess_views_view__taxonomy_term_custom(&$vars) {
  dpm($vars);
  // do stuff
}
0

Sure, that depends on which version of Drupal you are using though. Watch out for this issue. It says that you can't have a views preprocess function unless you have a corresponding tpl file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.