home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (xmlsitemap_i18n.module)

This example Drupal source code file (xmlsitemap_i18n.module) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, break, case, context, current, default, form, function, if, isset, language_none, mode, php, return

The xmlsitemap_i18n.module Drupal example source code

<?php
// $Id: xmlsitemap_i18n.module,v 1.16 2010/08/30 05:34:40 davereid Exp $

/**
 * Implements hook_xmlsitemap_context_info().
 */
function xmlsitemap_i18n_xmlsitemap_context_info() {
  $context['language'] = array(
    'label' => t('Language'),
    'summary callback' => 'locale_language_name',
    'default' => language_default('language'),
  );
  return $context;
}

/**
 * Implements hook_xmlsitemap_context().
 */
function xmlsitemap_i18n_xmlsitemap_context() {
  $context['language'] = $GLOBALS['language']->language;
  return $context;
}

/**
 * Implements xmlsitemap_context_url_options().
 */
function xmlsitemap_i18n_xmlsitemap_context_url_options(array $context) {
  $options = array();
  if (isset($context['language'])) {
    $options['language'] = xmlsitemap_language_load($context['language']);
  }
  return $options;
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function xmlsitemap_i18n_form_xmlsitemap_sitemap_edit_form_alter(&$form, $form_state) {
  $form['context']['language'] = array(
    '#type' => 'select',
    '#title' => t('Language'),
    '#options' => locale_language_list(),
    '#default_value' => isset($form['#sitemap']->context['language']) ? $form['#sitemap']->context['language'] : LANGUAGE_NONE,
  );
}

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

/**
 * 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_query_TAG_alter().
 *
 * @see i18n_db_rewrite_where()
 */
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 = 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.
      $query->condition('language', array($current, LANGUAGE_NONE));
      break;
    case 'mixed':
      // Mixed current language (if available) or default language (if not) and language neutral.
      $query->condition('language', array($current, $default, LANGUAGE_NONE));
      break;
    case 'default':
      // Only default language and language neutral.
      $query->condition('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('type', 'node');
      $node_condition->condition('language', $current);
      $normal_condition = db_and();
      $normal_condition->condition('type', 'node', '<>');
      $normal_condition->condition('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;
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal xmlsitemap_i18n.module source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.