diff --git a/i18n_access.module b/i18n_access.module index 5f4aa56..a76370d 100644 --- a/i18n_access.module +++ b/i18n_access.module @@ -105,18 +105,21 @@ function i18n_access_permission() { function i18n_access_form_node_form_alter(&$form, &$form_state, $form_id) { if (isset($form['language']['#options'])) { - // Remove inaccessible languages from the select box - // don't do it for admininstrators + // Remove inaccessible languages from the select box + // don't do it for administrators if (!user_access('administer nodes')) { $perms = i18n_access_load_permissions(); foreach ($form['language']['#options'] as $key => $value) { $perm_key = ($key == '') ? I18N_ACCESS_LANGUAGE_NEUTRAL : $key; - if ($key!='en' && empty($perms[$perm_key])) { + + // remove english from here, we treat english the same as any language + // if ($key!='en' && empty($perms[$perm_key])) { + if (empty($perms[$perm_key])) { unset($form['language']['#options']["$key"]); } } } - unset($form['#after_build']['0']); + // unset($form['#after_build']['0']); } } @@ -125,7 +128,7 @@ function i18n_access_form_node_form_alter(&$form, &$form_state, $form_id) { */ function i18n_access_form_alter(&$form, &$form_state, $form_id) { - //Configuring translation edit form to limit it to allowed language + // Configuring translation edit form to limit it to allowed language if ($form_id == 'i18n_node_select_translation' && !user_access('administer nodes')) { $perms = i18n_access_load_permissions(); @@ -149,7 +152,7 @@ function i18n_access_form_alter(&$form, &$form_state, $form_id) { } // Add i18n_access things to user/edit /user/add - if ($form_id == 'user_register_form' || $form_id == 'user_profile_form' ) { + if ($form_id == 'user_register_form' || $form_id == 'user_profile_form') { $form['i18n_access'] = array( '#type' => 'fieldset', @@ -171,67 +174,100 @@ function i18n_access_form_alter(&$form, &$form_state, $form_id) { * * @see node_access() */ -function i18n_access_node_access($node, $op, $account = NULL) { +function i18n_access_node_access($node, $op, $account = NULL, $langcode = NULL) { + // big re-work here. discarded entire original function-- replaced with our own if (is_object($node)) { - - global $user; - - // If no user object is supplied, the access check is for the current user. - if (empty($account)) { - $account = $user; + // make sure that site administrators always have access + $permissions = i18n_access_load_permissions($user); + if (user_access('site administrator', $account)) { + return TRUE; } + // if langcode is null it means the user is not accessing by translation overview, we throw access deny and allow to hard deny sneaky people and keep unpermitted tabs out of the menu system for the user + elseif ($langcode == NULL) { + global $language; + $langcode = $language->language; + + switch ($op) { + case 'view': + return NODE_ACCESS_ALLOW; + break; + case 'update': + if (empty($permissions[$langcode])) { + return NODE_ACCESS_DENY; + } + else { + return NODE_ACCESS_ALLOW; + } + break; + case 'create': + if (empty($permissions[$langcode])) { + return NODE_ACCESS_DENY; + } + else { + return NODE_ACCESS_ALLOW; + } + break; - // Bypass completely if node_access returns false. - //TODO $access = node_access($node, $op, $account); - - /* TODO if (!$access) { - return FALSE; - } */ - - // This module doesn't deal with view permissions - if ($op == 'view') { - return NODE_ACCESS_IGNORE; + } } - - // make sure that administrators always have access - if (user_access('administer nodes', $account)) { - return TRUE; + //if they are accessing by translation overview, the language code gets passed by the translation overview, we send true or false here + else { + switch ($op) { + case 'view': + return TRUE; + break; + case 'update': + if (empty($permissions[$langcode])) { + return FALSE; + } + else { + return TRUE; + } + break; + case 'create': + if (empty($permissions[$langcode])) { + return FALSE; + } + else { + return TRUE; + } + break; + } } - - $perms = i18n_access_load_permissions($account->uid); - - // Make sure to use the language neutral constant if node language is empty - $langcode = $node->language ? $node->language : I18N_ACCESS_LANGUAGE_NEUTRAL; - - //return isset($perms[$langcode]) ? (bool) $perms[$langcode] : NODE_ACCESS_DENY; - return isset($perms[$langcode]) ? NODE_ACCESS_ALLOW : NODE_ACCESS_DENY; } } /** * Implements hook_menu_alter(). */ -function i18n_access_menu_alter(&$items) { + +//make function name i18n_access_node_menu_alter +function i18n_access_node_menu_alter(&$items) { + + // due to hook_module_implementation_alter calling entity translation last, we can't change the callback here, i've done it in entity_translation.node.inc - consider calling it here? // Replace the translation overview page since we can't hook it. $items['node/%node/translate']['page callback'] = 'i18n_access_translation_node_overview'; + } function i18n_access_translation_node_overview($node) { include_once DRUPAL_ROOT . '/includes/language.inc'; - if (!empty($node->tnid)) { - // Already part of a set, grab that set. - $tnid = $node->tnid; - $translations = translation_node_get_translations($node->tnid); - } - else { - // We have no translation source nid, this could be a new set, emulate that. - $tnid = $node->nid; - $translations = array($node->language => $node); + // include functions from i18n_node.pages.inc + include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'i18n_node') . '/i18n_node.pages.inc'; + + // this is the part where this thing sorts out how to build a list of existing translations for this node + // since we use entity translation, the tnid isn't what we're using to build the translation list. we're using node->translations->data[keys] + $available_translations = $node->translations->data; + + // iterate over each available translation and add its key (which is the 2 letter language code) to the array we call $translations with the node object as the value + foreach ($available_translations as $key => $value) { + $translations[$key] = $node; } $type = variable_get('translation_language_type', LANGUAGE_TYPE_INTERFACE); + $header = array(t('Language'), t('Title'), t('Status'), t('Operations')); //added from i18n/i18n_node/i18n_node.pages.inc function @@ -240,9 +276,9 @@ function i18n_access_translation_node_overview($node) { $perms = i18n_access_load_permissions($account->uid); //end - // Modes have different allowed languages foreach (i18n_node_language_list($node) as $langcode => $language_name) { + if ($langcode == LANGUAGE_NONE) { // Never show language neutral on the overview. continue; @@ -253,16 +289,24 @@ function i18n_access_translation_node_overview($node) { // We load the full node to check whether the user can edit it. $translation_node = node_load($translations[$langcode]->nid); $path = 'node/' . $translation_node->nid; - $title = i18n_node_translation_link($translation_node->title, $path, $langcode); - if (node_access('update', $translation_node)) { + + // Account for title field module: + if (isset($translation_node->title_field) && isset($translation_node->title_field[$langcode])) { + $title = i18n_node_translation_link($translation_node->title_field[$langcode][0]['value'], $path, $langcode); + } + else { + $title = i18n_node_translation_link($translation_node->title, $path, $langcode); + } + + if (i18n_access_node_access($translation_node, 'update', $user, $langcode)) { $text = t('edit'); $path = 'node/' . $translation_node->nid . '/edit'; $options[] = i18n_node_translation_link($text, $path, $langcode); } $status = $translation_node->status ? t('Published') : t('Not published'); - $status .= $translation_node->translate ? ' - ' . t('outdated') . '' : ''; + $status .= $translation_node->translate ? ' - ' . t('outdated') . '' : ''; if ($translation_node->nid == $tnid) { - $language_name = t('@language_name (source)', array('@language_name' => $language_name)); + $language_name = t('@language_name (source)', array('@language_name' => $language_name)); } } else { @@ -316,6 +360,52 @@ function i18n_access_menu() { } /** + * Node-specific menu alterations. + */ +function i18n_access_menu_alter(&$items, $backup) { + if (isset($backup['node'])) { + $item = $backup['node']; + // Preserve the menu router item defined by other modules. + $callback['page callback'] = $item['page callback']; + $callback['file'] = $item['file']; + $callback['module'] = $item['module']; + $access_arguments = array_merge(array(1, $item['access callback']), $item['access arguments']); + } + else { + $access_arguments = array(1); + } + + // Point the 'translate' tab to point to the i18n_access version of the translation overview page + $items['node/%node/translate']['page callback'] = 'i18n_access_translation_node_overview'; + + // There are 3 page arguments for the entity translation overview, only one for i18n_access: + $items['node/%node/translate']['page arguments'] = array(1); + + // Pass in the i18n_access permissions + $items['node/%node/translate']['access arguments'] = $access_arguments; + + // Point to i18n_access's include for the callback + $items['node/%node/translate']['file'] = 'i18n_access.module'; + + // Point to i18n_access module + $items['node/%node/translate']['module'] = 'i18n_access'; +} + +/** + * Implements hook_module_implements_alter(). + */ +function i18n_access_module_implements_alter(&$implementations, $hook) { + switch ($hook) { + case 'menu_alter': + // Move our hook_menu_alter implementation to the end of the list. + $group = $implementations['i18n_access']; + unset($implementations['i18n_access']); + $implementations['i18n_access'] = $group; + break; + } +} + +/** * Admin settings form */ function i18n_access_admin_settings() { @@ -330,4 +420,4 @@ function i18n_access_admin_settings() { ); return system_settings_form($form); -} \ No newline at end of file +}