You are here

function xmlsitemap_i18n_query_xmlsitemap_generate_alter in XML sitemap 7.2

Same name and namespace in other branches
  1. 6.2 xmlsitemap_i18n/xmlsitemap_i18n.module \xmlsitemap_i18n_query_xmlsitemap_generate_alter()

Implements hook_query_TAG_alter().

See also

i18n_db_rewrite_where()

File

xmlsitemap_i18n/xmlsitemap_i18n.module, line 74
Main file for XML sitemap i18n.

Code

function xmlsitemap_i18n_query_xmlsitemap_generate_alter(QueryAlterableInterface $query) {
  $mode = variable_get('i18n_selection_mode', 'simple');
  $sitemap = $query
    ->getMetaData('sitemap');
  if (!isset($sitemap->context['language']) || $mode == 'off') {
    return;
  }

  // Get languages to simplify query building.
  $current = $sitemap->context['language'];
  $default = language_default('language');
  if ($mode == 'mixed' && $current == $default) {

    // If mode is mixed but current = default, is the same as 'simple'.
    $mode = 'simple';
  }
  switch ($mode) {
    case 'simple':

      // Current language and language neutral.
      $query
        ->condition('x.language', array(
        $current,
        LANGUAGE_NONE,
      ));
      break;
    case 'mixed':

      // Mixed current language (if available) or default language (if not) and
      // language neutral.
      $query
        ->condition('x.language', array(
        $current,
        $default,
        LANGUAGE_NONE,
      ));
      break;
    case 'default':

      // Only default language and language neutral.
      $query
        ->condition('x.language', array(
        $default,
        LANGUAGE_NONE,
      ));
      break;
    case 'strict':

      // Only current language (for nodes), simple for all other types.
      $node_condition = db_and();
      $node_condition
        ->condition('x.type', 'node');
      $node_condition
        ->condition('x.language', $current);
      $normal_condition = db_and();
      $normal_condition
        ->condition('x.type', 'node', '<>');
      $normal_condition
        ->condition('x.language', array(
        $current,
        LANGUAGE_NONE,
      ));
      $condition = db_or();
      $condition
        ->condition($node_condition);
      $condition
        ->condition($normal_condition);
      $query
        ->condition($condition);
      break;
    case 'off':

      // All content. No language conditions apply.
      break;
  }
}