I am using Pathauto to create automatic pathnames based on a CCK field.

The CCK field contains a name that includes a / character (e.g. XTC/RC-2412-MX) which is properly stripped by Pathauto, transforming the input into xtcrc-2412-mx.

My problem is that I need to create a page view using this value as an argument (using Path: items/%/parts) but it's clear that this argument won't match the CCK field content on the DB: there's is a missing /.

Is there a way to alter the Views query to add the / before quering the DB? The values are always having the / after the first three chars, so this could be easily done with preg_replace().

Comments

tomgf’s picture

I have created a very simple module to do this:

my_module.module

function my_module_views_query_alter(&$view, &$query) {

  if ('My_View'==$view->name):
    array_walk($query->where[0]['args'], 'do_replace');
  endif;

}

function do_replace(&$item, $key) {
  $pattern = '/xtc/i';
  $replacement = 'xtc/';
  $item = preg_replace($pattern, $replacement, $item);
}