Hi,
First of all, thanks for a great module!!.

I´m having problems with aliases and language negotiation.
I have my own implementation of hook_url_outbound_alter() in a custom module. I include domain name and langcode in a directory structure.

The issue is when hook_url_outbound_alter() is called from xmlsitemap_get_path_alias() the language is not passed as an option. Thus my hook is unaware of the node´s language and uses the default one which is wrong.

Current code...

//function xmlsitemap_get_path_alias($path, $language) { ....
//.....
// hook_url_outbound_alter() expects defaults in url() options.
  $options = array(
    'fragment' => '',
    'query' => array(),
    'absolute' => FALSE,
    'alias' => FALSE,
    'prefix' => '',
    'external' => FALSE,
  );

  if ($language != LANGUAGE_NONE && isset($aliases[$language][$path])) {
    $normalized_path = $aliases[$language][$path];
    $options['alias'] = TRUE;
  }
  elseif (isset($aliases[LANGUAGE_NONE][$path])) {
    $normalized_path = $aliases[LANGUAGE_NONE][$path];
    $options['alias'] = TRUE;
  }

  $original_path = $normalized_path;
  drupal_alter('url_outbound', $normalized_path, $options, $original_path);
  return $normalized_path;

Why don´t you pass language as options?. It´d be as simple as $options['language']=$language;. That way url_outbound_alter hooks would be aware of node´s language.

Just after executing xmlsitemap_get_path_alias(), in the same function you call url() (which in call calls url_outbound_alter again) and you do pass the language object. But this second time around my alias is already wrong... Actually moving "xmlsitemap_get_path_alias()" just under "link_options" and passing those would suffice. Is there a reason for not passing the same options to url_outbound_alter() than to url() ?.

if ($url_options['alias']) {
      $link['loc'] = xmlsitemap_get_path_alias($link['loc'], $link['language']->language);
    }
    $link_options = array(
      'language' => $link['language'],
      'xmlsitemap_link' => $link,
      'xmlsitemap_sitemap' => $sitemap,
    );
 // @todo Add a separate hook_xmlsitemap_link_url_alter() here?
    $link_url = url($link['loc'], $link_options + $url_options);

Thanks!!

Comments

tahiche created an issue.