Please consider the possibility to resolve path aliases regardless of the language of the node and/or the current language of the site while generating the links. If path alias is active, there shouldn't be any node/NID entries in the XML sitemap.

Thanks in advance.

Comments

Anonymous’s picture

Category: feature » support
Status: Active » Postponed (maintainer needs more info)

Resolution of the link is provided to us by core Drupal. Have you considered the Global Redirect module?

testosterone_z’s picture

Thank you for your prompt answer.

I'll try to clear things up a bit:

I'd like to generate one "sitemap.xml" containing all menu links of a drupal 6 website. The website has content in two languages: german (default) and english. Language negotiation is configured to use "path prefix only". The website doesn't use the "i18n" module, only the standard "locale" module. The site has two custom language specific menus ("Primary links (DE)", "Primary links (EN)", "Secondary links (DE)" and "Secondary links (EN)". The default "Primary" and "Secondary" links menus are disabled.

After including the menus on the xmlsitemap configuration page, the "sitemap.xml" did contain all menu links, but only the links from the "german" menus were printed as url aliases. The links from the "english" menus were given as "node/NID".

While browsing the "xmlsitemap_menu.module" code, I came to the conclusion, that the function "xmlsitemap_menu_create_link" is missing one option to set the correct language for a given menu link ($menu_item['xmlsitemap']['language']).

As far as i can tell, "$menu_item['options']['langcode']" will only be set by the "i18nmenu" module. If a menu link is created without this module, the "$menu_item['options'] will contain no language information whatsoever.

But one could query the "url_alias" table for the language entry of the "$menu_item['link_path']" and use that value for the "$menu_item['xmlsitemap']['language']" field.

Original function:

function xmlsitemap_menu_create_link(array $menu_item) {
  if (!isset($menu_item['xmlsitemap'])) {
    $menu_item['xmlsitemap'] = array();
    if ($menu_item['mlid'] && $link = xmlsitemap_link_load('menu_link', $menu_item['mlid'])) {
      $menu_item['xmlsitemap'] = $link;
    }
  }

  $settings = xmlsitemap_link_bundle_load('menu_link', $menu_item['menu_name']);

  $menu_item['xmlsitemap'] += array(
    'type' => 'menu_link',
    'id' => $menu_item['mlid'],
    'status' => $settings['status'],
    'status_default' => $settings['status'],
    'status_override' => 0,
    'priority' => $settings['priority'],
    'priority_default' => $settings['priority'],
    'priority_override' => 0,
  );

  // The following values must always be checked because they are volatile.
  $menu_item['xmlsitemap']['loc'] = $menu_item['link_path'];
  $menu_item['xmlsitemap']['subtype'] = $menu_item['menu_name'];
  $menu_item['xmlsitemap']['access'] = $menu_item['access'] && !$menu_item['external'] && !$menu_item['hidden'];
  $menu_item['xmlsitemap']['language'] = isset($menu_item['options']['langcode']) ? $menu_item['options']['langcode'] : '';

  return $menu_item['xmlsitemap'];
}

Function with url alias language check:

function xmlsitemap_menu_create_link(array $menu_item) {
  if (!isset($menu_item['xmlsitemap'])) {
    $menu_item['xmlsitemap'] = array();
    if ($menu_item['mlid'] && $link = xmlsitemap_link_load('menu_link', $menu_item['mlid'])) {
      $menu_item['xmlsitemap'] = $link;
    }
  }

  // url alias language check BEGIN
  $loc_langcode = '';
  if (isset($menu_item['options']['langcode'])) {
    $loc_langcode = $menu_item['options']['langcode'];
  } else {
    $query = db_query("SELECT language FROM {url_alias} WHERE src = '%s'",  $menu_item['link_path']);
    while ($alias = db_fetch_array($query)) {
      $loc_langcode = $alias['language'];
    }
  }
  // url alias language check END

  $settings = xmlsitemap_link_bundle_load('menu_link', $menu_item['menu_name']);

  $menu_item['xmlsitemap'] += array(
    'type' => 'menu_link',
    'id' => $menu_item['mlid'],
    'status' => $settings['status'],
    'status_default' => $settings['status'],
    'status_override' => 0,
    'priority' => $settings['priority'],
    'priority_default' => $settings['priority'],
    'priority_override' => 0,
  );

  // The following values must always be checked because they are volatile.
  $menu_item['xmlsitemap']['loc'] = $menu_item['link_path'];
  $menu_item['xmlsitemap']['subtype'] = $menu_item['menu_name'];
  $menu_item['xmlsitemap']['access'] = $menu_item['access'] && !$menu_item['external'] && !$menu_item['hidden'];
  // new link/url alias language assignment BEGIN
  $menu_item['xmlsitemap']['language'] = $loc_langcode;
  // new link/url alias language assignment BEGIN

  return $menu_item['xmlsitemap'];
}

This seems to work fine so far, because it only sets the correct language in the "xmlsitemap" table.

This code change most likely isn't good at all. But i think it get's the idea across. Hopefully you'll be able to find a better solution.

Anonymous’s picture

I feel a touch of déjà vu.

I remember some issue about the path module dealing with the language. I don't have any time to go researching it but if there is an issue it is with core. Your additional query will slow down an already slow process.