Fix for Fix for Setting view title when using a custom validator for a taxonomy_content field

  1. /**
  2.  * The previous code is the export of a view display which add a argument to filter nodes having a the passed term using name and synonyms
  3.  * as value for a taxonomy_content field. It works, but the title of the page is the tid returned by the validate_argument_php code and not the term's
  4.  * name.
  5.  * Since the view is exported in a custom module created with the features module (see http://drupal.org/project/features),
  6.  * the following preprocess_page function is used to overrides the title (and head_title).
  7.  */
  8.  
  9. function MYMODULE_preprocess_page(&$vars) {
  10.   if(arg(0) == VIEW_PATH && arg(1) && is_numeric($vars['title'])) {
  11.     $tid = (int)$vars['title'];
  12.     $term = taxonomy_get_term($tid);
  13.     if($term) {
  14.       $vars['title'] = check_plain($term->name);
  15.       $vars['head_title'] = str_replace($tid, check_plain($term->name), $vars['head_title']);
  16.     }
  17.   }
  18. }
  19.  
  20. /**
  21.  * The module also needs to set it weight to be greater than views' one (10) so its preprocess_page is called after views' one.
  22.  */
  23. function MYMODULE_install() {
  24.   db_query("UPDATE {system} SET weight = 11 WHERE name = 'MYMODULE'");
  25. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.