Hi,

I use views to browse children terms of a specified terms. It works pretty well except the page title.

I looked into the taxonomy_term default view to see how to set up the view to set the title as the term name instead of the term ID.

The default taxonomy_term views have a TID argument, and %1 as title, and it show the term name as title with a path like that : taxonomy/term/3

My view, that have a path like that : category/%, a TID argument and %1 as argument title show me a page with the title "3" with a path like that : category/3...

Why my views don't convert term TID into Term name as title whereas the taxonomy_term view do it ?

CommentFileSizeAuthor
#7 338893-taxonomy-argument-title.patch422 bytesdawehner

Comments

zmove’s picture

I'm still looking for a clean solution.

The only way I found is to create a temporary view title, to have the $title variable not empty in views-view-grid.tpl.php

And then, load the TID argument (arg(2)), load the term that have the tid of the argument, and show the $term->name instead of $title variable...

I think there is a cleaner way to do it, but didn't find it. Still looking for help.

Thanks

zmove

PS : It would be cool to have the value of the title in the $title variable when using arguments, instead of a hardcoded drupal_set_title. It would avoid the fact to be obliged to put a temporary title to be able to override it.

merlinofchaos’s picture

The validator is probably what's converting the title, though the argument is supposed to do it too.

merlinofchaos’s picture

Hm. I just tested this without the validator, and the title translation still happens.

Can you export your view?

zmove’s picture

Yes, no problem Here is it :

$view = new view;
$view->name = 'category_browse';
$view->description = 'Listing des différentes catégories';
$view->tag = 'custom';
$view->view_php = '';
$view->base_table = 'term_data';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Paramètres par défaut', 'default');
$handler->override_option('relationships', array(
  'parent' => array(
    'label' => 'Parent',
    'required' => 1,
    'id' => 'parent',
    'table' => 'term_hierarchy',
    'field' => 'parent',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Supplanter',
    ),
  ),
));
$handler->override_option('fields', array(
  'tid' => array(
    'label' => '',
    'imagecache_preset' => '',
    'link_to_taxonomy' => 1,
    'exclude' => 0,
    'id' => 'tid',
    'table' => 'term_image',
    'field' => 'tid',
    'relationship' => 'none',
  ),
  'name' => array(
    'label' => '',
    'link_to_taxonomy' => 1,
    'exclude' => 0,
    'id' => 'name',
    'table' => 'term_data',
    'field' => 'name',
    'relationship' => 'none',
  ),
  'description' => array(
    'label' => '',
    'exclude' => 0,
    'id' => 'description',
    'table' => 'term_data',
    'field' => 'description',
    'override' => array(
      'button' => 'Supplanter',
    ),
    'relationship' => 'none',
  ),
  'phpcode' => array(
    'label' => '',
    'value' => 'print l(\'» \'.t(\'View the category @category\', array(\'@category\' => $data->term_data_name)), \'taxonomy/term/\'.$data->tid)';,
    'exclude' => 0,
    'id' => 'phpcode',
    'table' => 'customfield',
    'field' => 'phpcode',
    'override' => array(
      'button' => 'Supplanter',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'tid' => array(
    'default_action' => 'not found',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => '',
    'wildcard_substitution' => 'Tous / Toutes',
    'title' => '%1',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'taxonomy_term',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'tid',
    'table' => 'term_data',
    'field' => 'tid',
    'relationship' => 'parent',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'simplenews' => 0,
      'product' => 0,
      'news' => 0,
      'page' => 0,
      'recipe' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '3' => 3,
      '4' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_php' => '',
    'override' => array(
      'button' => 'Supplanter',
    ),
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('header', 'Mysite marque d’ustensiles de cuisine contemporain, qui exprime avec justesse et émotion la créativité, en révélant le talent des plus grands noms du design et de la décoration. Mysite marque d’ustensiles de cuisine contemporain, qui exprime avec justesse et émotion la créativité, en révélant le talent des plus grands noms du design et de la décoration.');
$handler->override_option('header_format', '2');
$handler->override_option('header_empty', 0);
$handler->override_option('style_plugin', 'grid');
$handler->override_option('style_options', array(
  'grouping' => '',
  'columns' => '3',
  'alignment' => 'horizontal',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'category/%');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
));

I tested different configuration with arguments, without success. I would add that I would prefer to use tid instead of term name for argumens, it's quicker and safer IMHO.

Thank you for support.

merlinofchaos’s picture

Version: 6.x-2.1 » 6.x-2.8

Still valid. The reason this happens is that this is a taxonomy term view, not a node view, and thus it uses a different handler.

  // tid field
  $data['term_data']['tid'] = array(
    'title' => t('Term ID'),
    'help' => t('The taxonomy term ID'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
      'skip base' => array('node', 'node_revision'),
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_term_node_tid',
      'hierarchy table' => 'term_hierarchy',
      'numeric' => TRUE,
      'skip base' => array('node', 'node_revision'),
    ),
  );

The argument just uses the generic numeric handler and does not actually process the title, which is the problem. Using the taxonomy validator could work around this issue easily enough, but the bug should be fixed. I think we can set the title field to 'name' without creating a new handler.

yugene’s picture

Here is my quick solution:
1. Don't set title in views
2. in template.php

function MYTHEME_preprocess_views_view(&$vars){   
    drupal_set_title($vars['view']->build_info['substitutions']['%1']);
    return $vars;
}

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new422 bytes

Here we go.

merlinofchaos’s picture

Version: 6.x-2.8 » 7.x-3.x-dev
Status: Needs review » Patch (to be ported)

Committed to D6. Needs porting to D7.

dawehner’s picture

Status: Patch (to be ported) » Fixed

Ported and commited.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.