language_access.module in Language access 6
File
language_access.module
View source
<?php
function language_access_init() {
$path = $_GET['q'];
if ($path == 'user' || substr($path, 0, 5) == "user/") {
return;
}
global $language;
if (!user_access('access language ' . $language->language)) {
$default_language = language_default();
if ($language->language != $default_language->language) {
if (php_sapi_name() != 'cli') {
drupal_access_denied();
exit;
}
}
}
}
function language_access_perm() {
$perms = array();
$languages = language_list('enabled');
foreach ($languages[1] as $language) {
array_push($perms, 'access language ' . $language->language, 'create language ' . $language->language);
}
return $perms;
}
function language_access_translation_link_alter(&$links, $path) {
$languages = language_list('enabled');
foreach ($languages[1] as $language) {
if (!user_access('access language ' . $language->language)) {
if (isset($links[$language->language])) {
unset($links[$language->language]);
}
}
}
}
function language_access_link_alter(&$links, $node, $comment = NULL) {
$languages = language_list('enabled');
foreach ($languages[1] as $language) {
if (!user_access('access language ' . $language->language)) {
if (isset($links['node_translation_' . $language->language])) {
unset($links['node_translation_' . $language->language]);
}
}
}
}
function language_access_form_alter(&$form, &$form_state, $form_id) {
if ($form['#id'] == 'node-form') {
$form['#after_build'][] = '_language_access_form_node_form_alter';
}
}
function _language_access_form_node_form_alter($form, &$form_state) {
$default_value = $form['language']['#default_value'];
if (!empty($default_value)) {
if (!user_access('create language ' . $default_value) && $default_value != 'und') {
drupal_access_denied();
exit;
}
}
$default_language = language_default();
if (isset($form['language']['#options'])) {
foreach ($form['language']['#options'] as $lang => $lang_name) {
if ($lang != 'und' && $lang != $default_language->language) {
if (!user_access('create language ' . $lang)) {
unset($form['language']['#options'][$lang]);
}
}
}
}
return $form;
}