I am working in Drupal and trying to return a new URL in the lower function. The trouble I am having is that the $path
variable I am returning doesn't persist the $vocab
and $site
variable.
Also, for non-Drupal users, the ccw_taxonomy_baseurl_filter_url_inbound_alter()
function is automatically called so that is not the problem. I am hoping this is a syntax issue or something inside the switch because I have spent a lot of time debugging this.
function __extractURLName($myurl){
$domain = parse_url($myurl , PHP_URL_HOST);
if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $list)) {
return substr($list['domain'], 0,strpos($list['domain'], "."));
}
return false;
}
/**
* Implements hook_url_inbound_alter().
*/
function ccw_taxonomy_baseurl_filter_url_inbound_alter(&$path, $original_path, $path_language) {
if($path =='taxonomy/term/%'){
$path = '';
$url = __extractURLName(url(NULL, array('absolute' => TRUE)));
$site = 0;
$vocab = arg(2);
switch ($url) {
case 'bmagazine':
$site = 5;
$vocab = arg(2);
break;
case 'emagazine':
if (arg(0) == 'high') {
$site = 4;
$vocab = arg(3);
break;
} else {
$site = 3;
$vocab = arg(3);
break;
}
case 'smagazine':
$site = 2;
$vocab = arg(2);
break;
case 'fmagazine':
$site = 1;
$vocab = arg(2);
break;
default:
$site = 1;
break;
}
$path = 'taxonomy/term/'.$vocab.'/'.$site;
}
dpm($path); // debugging tool
return $path;
}
By the way, arg()
is a drupal function as well that grabs a URL path variable.
Check comments for answer under the question for more detail, but I solved the problem by changed the path