You are here

administration_language_negotiation.module in Administration Language Negotiation 7

Same filename and directory in other branches
  1. 8 administration_language_negotiation.module

Main module page of administration language negotiation module.

File

administration_language_negotiation.module
View source
<?php

/**
 * @file
 * Main module page of administration language negotiation module.
 */
define('LANGUAGE_NEGOTIATION_ADMINISTRATION', 'language-administration');

/**
 * Implements hook_menu().
 */
function administration_language_negotiation_menu() {
  $items = array();
  $items['admin/config/regional/language/configure/administration_language'] = array(
    'title' => 'Administration language negotiation',
    'description' => 'Configure the administration language negotiation',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'administration_language_negotiation_admin',
    ),
    'access arguments' => array(
      'administer languages',
    ),
    'file' => 'administration_language_negotiation.admin.inc',
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
  );
  return $items;
}

/**
 * Implements hook_language_negotiation_info().
 */
function administration_language_negotiation_language_negotiation_info() {
  return array(
    LANGUAGE_NEGOTIATION_ADMINISTRATION => array(
      'types' => array(
        LANGUAGE_TYPE_INTERFACE,
      ),
      'callbacks' => array(
        'language' => 'administration_language_negotiation_admin_language',
      ),
      'file' => drupal_get_path('module', 'administration_language_negotiation') . '/administration_language_negotiation.module',
      'weight' => -50,
      'name' => t('Administration path'),
      'description' => t('Set a default language on specific paths.'),
      'config' => 'admin/config/regional/language/configure/administration_language',
      'cache' => 0,
    ),
  );
}

/**
 * Language negotiation custom callback.
 */
function administration_language_negotiation_admin_language() {
  require_once 'includes/path.inc';
  if (_administration_language_negotiation_admin_get_language(current_path())) {
    return variable_get('administration_language_negotiation_default', FALSE);
  }
  return FALSE;
}

/**
 * Custom callback to check if a path match a list of path.
 *
 * @param string $path_to_check
 *   The path to check.
 *
 * @return bool
 *   True if the path match, False otherwise.
 */
function _administration_language_negotiation_admin_get_language($path_to_check) {
  $admin_path = implode("\n", array_filter(variable_get('administration_language_negotiation_paths', array())));
  if (drupal_match_path($path_to_check, $admin_path)) {
    return TRUE;
  }
  return FALSE;
}

Functions

Constants

Namesort descending Description
LANGUAGE_NEGOTIATION_ADMINISTRATION @file Main module page of administration language negotiation module.