content_language_access.module in Content Language Access 7
Same filename and directory in other branches
Include language permissions to modify content.
This module provides access checking of the current language of the site with the language of the content (language neutral are not considered).
File
content_language_access.moduleView source
<?php
/**
* @file
* Include language permissions to modify content.
*
* This module provides access checking of the current language of the site
* with the language of the content (language neutral are not considered).
*/
/**
* Implements hook_menu().
*/
function content_language_access_menu() {
$items['admin/config/regional/content_language_access'] = array(
'title' => 'Content language access',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'content_language_access_admin_form',
),
'access arguments' => array(
'administer content_language_access settings',
),
'file' => 'content_language_access.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implements hook_node_access().
*
* @global object $language
*/
function content_language_access_node_access($node, $op, $account) {
global $language;
// Only checks for view permission.
if (is_object($node) && $op == 'view') {
$translation_enabled = locale_multilingual_node_type($node->type);
// Ignoring when node is not translatable or the language is neutral.
if ($translation_enabled && $node->language && $node->language != LANGUAGE_NONE) {
// Verifies if the current language is the same of the content.
if ($node->language != $language->language) {
// Ignore verification while translating content. Drupal passes the
// translation and target parameters during the translation.
// Example: node/add/article?translation=8&target=pt-br
if (drupal_match_path(drupal_get_path_alias(), 'node/add/*') && isset($_GET['translation']) && isset($_GET['target'])) {
return NODE_ACCESS_IGNORE;
}
// Checks the configuration defined in admin page.
$config = _content_language_access_get_config();
$actual_language_permission = isset($config[$language->language][$node->language]) ? $config[$language->language][$node->language] : FALSE;
if (!$actual_language_permission && !user_access('bypass content_language_access', $account)) {
return NODE_ACCESS_DENY;
}
}
}
}
return NODE_ACCESS_IGNORE;
}
/**
* Implements hook_help().
*/
function content_language_access_help($path, $arg) {
switch ($path) {
// Main module help for the content_language_access module.
case 'admin/help#content_language_access':
return '<p>' . t('Content Language Access Module restricts the access of only contents with language (except neutral language) that are equal of the actual Drupal language being accessed or others that were previous configured in the <a href="@content_language_access">admin page</a>.', array(
'@content_language_access' => url('admin/config/regional/content_language_access'),
)) . '</p>';
// Help for admin page for the content_language_access module.
case 'admin/config/regional/content_language_access':
return '<p>' . t('This page provides an interface for configuring more languages that can be accessed from a Drupal language') . '</p>';
}
}
/**
* Implements hook_permission().
*/
function content_language_access_permission() {
return array(
'administer content_language_access settings' => array(
'title' => t('Administer Content Language Access'),
'description' => t('Perform administration tasks for Content Language Access.'),
),
'bypass content_language_access' => array(
'title' => t('Bypass Content Language Access restriction'),
'description' => t("Allow users to access content in other languages than current site's language."),
),
);
}
/**
* Helper to get all the config available for the module.
*
* @return array
* All configuration from admin/config/regional/content_language_access page.
*/
function _content_language_access_get_config() {
return variable_get('content_language_access', array());
}
Functions
Name | Description |
---|---|
content_language_access_help | Implements hook_help(). |
content_language_access_menu | Implements hook_menu(). |
content_language_access_node_access | Implements hook_node_access(). |
content_language_access_permission | Implements hook_permission(). |
_content_language_access_get_config | Helper to get all the config available for the module. |