handled translation links from node edit
This commit is contained in:
parent
669341f1d6
commit
7563311a19
@ -46,7 +46,12 @@ function materio_translator_user_delete($account) {
|
|||||||
->execute();
|
->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// __ __ __
|
||||||
|
// / / / /__ / /___ ___ __________
|
||||||
|
// / /_/ / _ \/ / __ \/ _ \/ ___/ ___/
|
||||||
|
// / __ / __/ / /_/ / __/ / (__ )
|
||||||
|
// /_/ /_/\___/_/ .___/\___/_/ /____/
|
||||||
|
// /_/
|
||||||
/**
|
/**
|
||||||
* Load the language permissions for a given user
|
* Load the language permissions for a given user
|
||||||
*/
|
*/
|
||||||
@ -80,6 +85,12 @@ function materio_translator_load_permissions($uid = NULL) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ________ __ __
|
||||||
|
// / ____/ /___ / /_ ____ _/ / ____ ___ _________ ___ _____
|
||||||
|
// / / __/ / __ \/ __ \/ __ `/ / / __ \/ _ \/ ___/ __ `__ \/ ___/
|
||||||
|
// / /_/ / / /_/ / /_/ / /_/ / / / /_/ / __/ / / / / / / (__ )
|
||||||
|
// \____/_/\____/_.___/\__,_/_/ / .___/\___/_/ /_/ /_/ /_/____/
|
||||||
|
// /_/
|
||||||
/**
|
/**
|
||||||
* Implements hook_permission().
|
* Implements hook_permission().
|
||||||
*/
|
*/
|
||||||
@ -90,6 +101,11 @@ function materio_translator_permission() {
|
|||||||
'description' => t('This permission gives this role edit/delete access to all content which are in the <a href="!url" target="_blank">selected language</a>. View/create access needs a different access level.', array('!url' => url('admin/config/regional/language/access'))),
|
'description' => t('This permission gives this role edit/delete access to all content which are in the <a href="!url" target="_blank">selected language</a>. View/create access needs a different access level.', array('!url' => url('admin/config/regional/language/access'))),
|
||||||
'restrict access' => TRUE,
|
'restrict access' => TRUE,
|
||||||
),
|
),
|
||||||
|
'administer user translation language access' => array(
|
||||||
|
'title' => t('Administer user translation language access'),
|
||||||
|
'description' => t('administer user translation language access'),
|
||||||
|
'restrict access' => TRUE,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +123,7 @@ function materio_translator_form_alter(&$form, &$form_state, $form_id) {
|
|||||||
'#type' => 'fieldset',
|
'#type' => 'fieldset',
|
||||||
'#title' => t('Translation access'),
|
'#title' => t('Translation access'),
|
||||||
'#tree' => 0,
|
'#tree' => 0,
|
||||||
'#access' => user_access('administer users'),
|
'#access' => user_access('administer user translation language access'),
|
||||||
);
|
);
|
||||||
$form['materio_translator']['materio_translator'] = array(
|
$form['materio_translator']['materio_translator'] = array(
|
||||||
'#type' => 'checkboxes',
|
'#type' => 'checkboxes',
|
||||||
@ -116,11 +132,8 @@ function materio_translator_form_alter(&$form, &$form_state, $form_id) {
|
|||||||
'#description' => t('The user get edit, delete access to all content which are in this enabled languages. Create, view access needs a different access level.'),
|
'#description' => t('The user get edit, delete access to all content which are in this enabled languages. Create, view access needs a different access level.'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_menu().
|
* Implements hook_menu().
|
||||||
*/
|
*/
|
||||||
@ -151,12 +164,11 @@ function materio_translator_admin_settings($form) {
|
|||||||
return system_settings_form($form);
|
return system_settings_form($form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// __ ___ ___ ____
|
||||||
// _ __ __ _
|
// / |/ /__ ____ __ __ / | / / /____ _____
|
||||||
// / | / /___ ____/ /__ ____ _ _____ ______ __(_)__ _ __
|
// / /|_/ / _ \/ __ \/ / / / / /| | / / __/ _ \/ ___/
|
||||||
// / |/ / __ \/ __ / _ \ / __ \ | / / _ \/ ___/ | / / / _ \ | /| / /
|
// / / / / __/ / / / /_/ / / ___ |/ / /_/ __/ /
|
||||||
// / /| / /_/ / /_/ / __/ / /_/ / |/ / __/ / | |/ / / __/ |/ |/ /
|
// /_/ /_/\___/_/ /_/\__,_/ /_/ |_/_/\__/\___/_/
|
||||||
// /_/ |_/\____/\__,_/\___/ \____/|___/\___/_/ |___/_/\___/|__/|__/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_menu_alter().
|
* Implements hook_menu_alter().
|
||||||
@ -182,48 +194,95 @@ function materio_translator_menu_alter(&$items) {
|
|||||||
// dsm($pargs, "pargs");
|
// dsm($pargs, "pargs");
|
||||||
|
|
||||||
// change page callback for our own function
|
// change page callback for our own function
|
||||||
$items["node/%node/translate"]['page callback'] = "materio_translator_translation_node_overview";
|
$items[$path]['page callback'] = "materio_translator_translation_node_overview";
|
||||||
// add our own page raguments
|
// add our own page raguments
|
||||||
$items["node/%node/translate"]['page arguments'] = $pargs;
|
$items[$path]['page arguments'] = $pargs;
|
||||||
/*
|
}
|
||||||
original $item :
|
|
||||||
Array(
|
|
||||||
[title] => Translate
|
|
||||||
[page callback] => entity_translation_overview
|
|
||||||
[page arguments] => Array
|
|
||||||
(
|
|
||||||
[0] => node
|
|
||||||
[1] => 1
|
|
||||||
[2] => Array
|
|
||||||
(
|
|
||||||
[page callback] => i18n_node_translation_overview
|
|
||||||
[file] => i18n_node.pages.inc
|
|
||||||
[module] => i18n_node
|
|
||||||
)
|
|
||||||
|
|
||||||
[3] => 1
|
// translation edit link
|
||||||
)
|
if(preg_match('/^node\/%node\/edit\/%entity_translation_language$/', $path)){
|
||||||
|
// dsm($item, $path);
|
||||||
|
|
||||||
[type] => 132
|
// create new page arguments
|
||||||
[weight] => 1
|
$access_args = $item['access arguments'];
|
||||||
[context] => 3
|
// dsm($access_args, 'access_args avt');
|
||||||
[access callback] => entity_translation_node_tab_access
|
// add page call back for entity_translation call
|
||||||
[access arguments] => Array
|
// and memorize old page callback (i18n) for entity_translation call args
|
||||||
(
|
$access_args[3]['access callback'] = $item['access callback'];
|
||||||
[0] => 1
|
$access_args[3]['file'] = 'entity_translation.node.inc';
|
||||||
[1] => _translation_tab_access
|
$access_args[3]['module'] = 'entity_translation';
|
||||||
[2] => 1
|
$access_args[3]['access arguments'] = $item['access arguments'];
|
||||||
)
|
// dsm($access_args, "access_args");
|
||||||
|
|
||||||
|
// change access callback for our own function
|
||||||
|
$items[$path]['access callback'] = 'materio_translator_node_edit_access';
|
||||||
|
// add our own page raguments
|
||||||
|
$items[$path]['access arguments'] = $access_args;
|
||||||
|
// dsm($access_args, 'access_args apr');
|
||||||
|
|
||||||
|
// dsm($items[$path], $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// translation add link
|
||||||
|
if(preg_match('/^node\/%node\/edit\/add\/%entity_translation_language/', $path)){
|
||||||
|
// dsm($item, $path);
|
||||||
|
|
||||||
[file] => entity_translation.admin.inc
|
|
||||||
[module] => entity_translation
|
|
||||||
)
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function materio_translator_node_edit_access($entity_type, $entity, $langcode, $callback = null){
|
||||||
|
$args = func_get_args();
|
||||||
|
// dsm($args, '1 -- materio_translator_node_edit_access args');
|
||||||
|
|
||||||
|
// dsm($entity_type, "entity_type");
|
||||||
|
// dsm($entity, "entity");
|
||||||
|
// dsm($langcode, 'langcode');
|
||||||
|
// dsm($callback, "2 -- callback");
|
||||||
|
|
||||||
|
if (module_exists($callback['module'])) {
|
||||||
|
// dsm('module_exists');
|
||||||
|
if (isset($callback['file'])) {
|
||||||
|
$path = isset($callback['file path']) ? $callback['file path'] : drupal_get_path('module', $callback['module']);
|
||||||
|
// dsm($path, 'path');
|
||||||
|
require_once DRUPAL_ROOT . '/' . $path . '/' . $callback['file'];
|
||||||
|
}
|
||||||
|
// dsm($callback['access callback'], 'access callback');
|
||||||
|
$callback['access arguments'][1] = $entity;
|
||||||
|
$callback['access arguments'][2] = $langcode;
|
||||||
|
$callback['access arguments'][5] = $entity;
|
||||||
|
// dsm($callback['access arguments'], "callback['access arguments']");
|
||||||
|
$callbackaccess = call_user_func_array($callback['access callback'], $callback['access arguments']);
|
||||||
|
// dsm($callbackaccess, '3 -- callbackaccess');
|
||||||
|
|
||||||
|
if($callbackaccess){
|
||||||
|
global $user;
|
||||||
|
$perms = materio_translator_load_permissions($user->uid);
|
||||||
|
// dsm($perms, '4 -- perms');
|
||||||
|
// remove link if langcode not in perms
|
||||||
|
if(in_array($langcode, $perms)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// $callbackaccess = call_user_func_array($callback['access callback'], $callback['access arguments']);
|
||||||
|
|
||||||
|
// return $callbackaccess;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// _ __ __ _
|
||||||
|
// / | / /___ ____/ /__ ____ _ _____ ______ __(_)__ _ __
|
||||||
|
// / |/ / __ \/ __ / _ \ / __ \ | / / _ \/ ___/ | / / / _ \ | /| / /
|
||||||
|
// / /| / /_/ / /_/ / __/ / /_/ / |/ / __/ / | |/ / / __/ |/ |/ /
|
||||||
|
// /_/ |_/\____/\__,_/\___/ \____/|___/\___/_/ |___/_/\___/|__/|__/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_module_implements_alter().
|
* Implements hook_module_implements_alter().
|
||||||
*/
|
*/
|
||||||
@ -251,6 +310,7 @@ function materio_translator_module_implements_alter(&$implementations, $hook) {
|
|||||||
* @return array.
|
* @return array.
|
||||||
*/
|
*/
|
||||||
function materio_translator_translation_node_overview($entity_type, $entity, $callback = NULL) {
|
function materio_translator_translation_node_overview($entity_type, $entity, $callback = NULL) {
|
||||||
|
// dsm('materio_translator_translation_node_overview');
|
||||||
// dsm($entity_type, "entity_type");
|
// dsm($entity_type, "entity_type");
|
||||||
// dsm($entity, "entity");
|
// dsm($entity, "entity");
|
||||||
// dsm($callback, "callback");
|
// dsm($callback, "callback");
|
||||||
@ -301,3 +361,113 @@ function materio_translator_overview_callback($callback) {
|
|||||||
return call_user_func_array($callback['page callback'], $callback['page arguments']);
|
return call_user_func_array($callback['page callback'], $callback['page arguments']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// _ __ __ __
|
||||||
|
// / | / /___ ____/ /__ / /___ _____ ____ ___ ______ _____ ____
|
||||||
|
// / |/ / __ \/ __ / _ \ / / __ `/ __ \/ __ `/ / / / __ `/ __ `/ _ \
|
||||||
|
// / /| / /_/ / /_/ / __/ / / /_/ / / / / /_/ / /_/ / /_/ / /_/ / __/
|
||||||
|
// /_/ |_/\____/\__,_/\___/ __/\__,_/_/ /_/\__, /\__,_/\__,_/\__, /\___/
|
||||||
|
// ________ / /__ _____/ /_(_)___ ___/____/ /____/
|
||||||
|
// / ___/ _ \/ / _ \/ ___/ __/ / __ \/ __ \
|
||||||
|
// (__ ) __/ / __/ /__/ /_/ / /_/ / / / /
|
||||||
|
// /____/\___/_/\___/\___/\__/_/\____/_/ /_/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_menu_local_tasks_alter().
|
||||||
|
*/
|
||||||
|
function materio_translator_menu_local_tasks_alter(&$data, $router_item, $root_path) {
|
||||||
|
// dsm($data, 'data');
|
||||||
|
|
||||||
|
global $user;
|
||||||
|
$perms = materio_translator_load_permissions($user->uid);
|
||||||
|
|
||||||
|
foreach ($data['tabs'] as $t => $tab) {
|
||||||
|
foreach ($tab['output'] as $l => $link) {
|
||||||
|
if($link['#language_tab']){
|
||||||
|
// dsm($link, $link["#link"]["title"]);
|
||||||
|
$langcode = $link["#link"]['localized_options']['language']->language;
|
||||||
|
if(!in_array($langcode, $perms)){
|
||||||
|
unset($data['tabs'][$t]['output'][$l]);
|
||||||
|
}
|
||||||
|
// dsm($data['tabs'][$t]['output'][$l]['#link']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_form_node_form_alter().
|
||||||
|
*/
|
||||||
|
function materio_translator_form_node_form_alter(&$form) {
|
||||||
|
$form['#after_build'][] = '_materio_translator_form_node_form_alter';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unset's languages from language options if user does not have permission to
|
||||||
|
* use.
|
||||||
|
*
|
||||||
|
* @param $form
|
||||||
|
* @param $form_state
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function _materio_translator_form_node_form_alter($form, &$form_state) {
|
||||||
|
if (isset($form['language']['#options']) && !user_access('bypass node access')) {
|
||||||
|
$perms = materio_translator_load_permissions();
|
||||||
|
foreach ($form['language']['#options'] as $key => $value) {
|
||||||
|
if (empty($perms[$key])) {
|
||||||
|
unset($form['language']['#options'][$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function materio_translator_node_tab_access(){
|
||||||
|
$args = func_get_args();
|
||||||
|
dsm($args, '1 -- materio_translator_node_tab_access args');
|
||||||
|
|
||||||
|
// dsm($entity_type, "entity_type");
|
||||||
|
// dsm($entity, "entity");
|
||||||
|
// dsm($langcode, 'langcode');
|
||||||
|
// dsm($callback, "2 -- callback");
|
||||||
|
/*
|
||||||
|
if (module_exists($callback['module'])) {
|
||||||
|
// dsm('module_exists');
|
||||||
|
if (isset($callback['file'])) {
|
||||||
|
$path = isset($callback['file path']) ? $callback['file path'] : drupal_get_path('module', $callback['module']);
|
||||||
|
// dsm($path, 'path');
|
||||||
|
require_once DRUPAL_ROOT . '/' . $path . '/' . $callback['file'];
|
||||||
|
}
|
||||||
|
// dsm($callback['access callback'], 'access callback');
|
||||||
|
$callback['access arguments'][1] = $entity;
|
||||||
|
$callback['access arguments'][2] = $langcode;
|
||||||
|
$callback['access arguments'][5] = $entity;
|
||||||
|
// dsm($callback['access arguments'], "callback['access arguments']");
|
||||||
|
$callbackaccess = call_user_func_array($callback['access callback'], $callback['access arguments']);
|
||||||
|
// dsm($callbackaccess, '3 -- callbackaccess');
|
||||||
|
|
||||||
|
if($callbackaccess){
|
||||||
|
global $user;
|
||||||
|
$perms = materio_translator_load_permissions($user->uid);
|
||||||
|
// dsm($perms, '4 -- perms');
|
||||||
|
// remove link if langcode not in perms
|
||||||
|
if(in_array($langcode, $perms)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// $callbackaccess = call_user_func_array($callback['access callback'], $callback['access arguments']);
|
||||||
|
|
||||||
|
// return $callbackaccess;
|
||||||
|
*/
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user