xmlsitemap_i18n.module 2.42 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
// $Id$

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Set the regeneration needed flag if multilingual settings are changed.
 */
function xmlsitemap_i18n_form_i18n_admin_settings_alter(&$form, $form_state) {
  array_unshift($form['#submit'], 'xmlsitemap_form_submit_flag_regenerate');
}

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Allow the user to have multilingual sitemaps.
 */
function xmlsitemap_i18n_form_xmlsitemap_settings_form_alter(&$form, $form_state) {
  $form['xmlsitemap']['xmlsitemap_languages']['#options'] = locale_language_list();
  $form['xmlsitemap']['xmlsitemap_languages']['#description'] = t("Each language's sitemap will respect the <a href=\"@i18n-settings\">multilingual content selection mode</a>.", array('@i18n-settings' => url('admin/settings/language/i18n')));
}

/**
24
 * Implements hook_query_TAG_alter().
25
26
27
 *
 * @see i18n_db_rewrite_where()
 */
28
function xmlsitemap_i18n_query_xmlsitemap_alter(QueryAlterableInterface $query) {
29
30
  // Get languages to simplify query building.
  $mode = variable_get('i18n_selection_mode', 'simple');
31
  $current = $query->getMetaData('language')->language;
32
33
34
35
36
37
38
39
40
41
  $default = i18n_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.
42
      $query->condition('language', array($current, ''));
43
44
45
      break;
    case 'mixed':
      // Mixed current language (if available) or default language (if not) and language neutral.
46
      $query->condition('language', array($current, $default, ''));
47
48
49
      break;
    case 'default':
      // Only default language and language neutral.
50
      $query->condition('language', array($default, ''));
51
52
53
      break;
    case 'strict':
      // Only current language (for nodes), simple for all other types.
54
55
56
57
58
59
60
61
62
63
      $node_condition = db_and();
      $node_condition->condition('type', 'node');
      $node_condition->condition('language', $current);
      $normal_condition = db_and();
      $normal_condition->condition('type', 'node', '<>');
      $normal_condition->condition('language', array($current, ''));
      $condition = db_or();
      $condition->condition($node_condition);
      $condition->condition($normal_condition);
      $query->condition($condition);
64
65
66
67
68
69
      break;
    case 'off':
      // All content. No language conditions apply.
      break;
  }
}