entity_translation-2211649-5.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. diff --git a/i18n_access.module b/i18n_access.module
  2. index 5f4aa56..a76370d 100644
  3. --- a/i18n_access.module
  4. +++ b/i18n_access.module
  5. @@ -105,18 +105,21 @@ function i18n_access_permission() {
  6. function i18n_access_form_node_form_alter(&$form, &$form_state, $form_id) {
  7. if (isset($form['language']['#options'])) {
  8. - // Remove inaccessible languages from the select box
  9. - // don't do it for admininstrators
  10. + // Remove inaccessible languages from the select box
  11. + // don't do it for administrators
  12. if (!user_access('administer nodes')) {
  13. $perms = i18n_access_load_permissions();
  14. foreach ($form['language']['#options'] as $key => $value) {
  15. $perm_key = ($key == '') ? I18N_ACCESS_LANGUAGE_NEUTRAL : $key;
  16. - if ($key!='en' && empty($perms[$perm_key])) {
  17. +
  18. + // remove english from here, we treat english the same as any language
  19. + // if ($key!='en' && empty($perms[$perm_key])) {
  20. + if (empty($perms[$perm_key])) {
  21. unset($form['language']['#options']["$key"]);
  22. }
  23. }
  24. }
  25. - unset($form['#after_build']['0']);
  26. + // unset($form['#after_build']['0']);
  27. }
  28. }
  29. @@ -125,7 +128,7 @@ function i18n_access_form_node_form_alter(&$form, &$form_state, $form_id) {
  30. */
  31. function i18n_access_form_alter(&$form, &$form_state, $form_id) {
  32. - //Configuring translation edit form to limit it to allowed language
  33. + // Configuring translation edit form to limit it to allowed language
  34. if ($form_id == 'i18n_node_select_translation' && !user_access('administer nodes')) {
  35. $perms = i18n_access_load_permissions();
  36. @@ -149,7 +152,7 @@ function i18n_access_form_alter(&$form, &$form_state, $form_id) {
  37. }
  38. // Add i18n_access things to user/edit /user/add
  39. - if ($form_id == 'user_register_form' || $form_id == 'user_profile_form' ) {
  40. + if ($form_id == 'user_register_form' || $form_id == 'user_profile_form') {
  41. $form['i18n_access'] = array(
  42. '#type' => 'fieldset',
  43. @@ -171,67 +174,100 @@ function i18n_access_form_alter(&$form, &$form_state, $form_id) {
  44. *
  45. * @see node_access()
  46. */
  47. -function i18n_access_node_access($node, $op, $account = NULL) {
  48. +function i18n_access_node_access($node, $op, $account = NULL, $langcode = NULL) {
  49. + // big re-work here. discarded entire original function-- replaced with our own
  50. if (is_object($node)) {
  51. -
  52. - global $user;
  53. -
  54. - // If no user object is supplied, the access check is for the current user.
  55. - if (empty($account)) {
  56. - $account = $user;
  57. + // make sure that site administrators always have access
  58. + $permissions = i18n_access_load_permissions($user);
  59. + if (user_access('site administrator', $account)) {
  60. + return TRUE;
  61. }
  62. + // 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
  63. + elseif ($langcode == NULL) {
  64. + global $language;
  65. + $langcode = $language->language;
  66. +
  67. + switch ($op) {
  68. + case 'view':
  69. + return NODE_ACCESS_ALLOW;
  70. + break;
  71. + case 'update':
  72. + if (empty($permissions[$langcode])) {
  73. + return NODE_ACCESS_DENY;
  74. + }
  75. + else {
  76. + return NODE_ACCESS_ALLOW;
  77. + }
  78. + break;
  79. + case 'create':
  80. + if (empty($permissions[$langcode])) {
  81. + return NODE_ACCESS_DENY;
  82. + }
  83. + else {
  84. + return NODE_ACCESS_ALLOW;
  85. + }
  86. + break;
  87. - // Bypass completely if node_access returns false.
  88. - //TODO $access = node_access($node, $op, $account);
  89. -
  90. - /* TODO if (!$access) {
  91. - return FALSE;
  92. - } */
  93. -
  94. - // This module doesn't deal with view permissions
  95. - if ($op == 'view') {
  96. - return NODE_ACCESS_IGNORE;
  97. + }
  98. }
  99. -
  100. - // make sure that administrators always have access
  101. - if (user_access('administer nodes', $account)) {
  102. - return TRUE;
  103. + //if they are accessing by translation overview, the language code gets passed by the translation overview, we send true or false here
  104. + else {
  105. + switch ($op) {
  106. + case 'view':
  107. + return TRUE;
  108. + break;
  109. + case 'update':
  110. + if (empty($permissions[$langcode])) {
  111. + return FALSE;
  112. + }
  113. + else {
  114. + return TRUE;
  115. + }
  116. + break;
  117. + case 'create':
  118. + if (empty($permissions[$langcode])) {
  119. + return FALSE;
  120. + }
  121. + else {
  122. + return TRUE;
  123. + }
  124. + break;
  125. + }
  126. }
  127. -
  128. - $perms = i18n_access_load_permissions($account->uid);
  129. -
  130. - // Make sure to use the language neutral constant if node language is empty
  131. - $langcode = $node->language ? $node->language : I18N_ACCESS_LANGUAGE_NEUTRAL;
  132. -
  133. - //return isset($perms[$langcode]) ? (bool) $perms[$langcode] : NODE_ACCESS_DENY;
  134. - return isset($perms[$langcode]) ? NODE_ACCESS_ALLOW : NODE_ACCESS_DENY;
  135. }
  136. }
  137. /**
  138. * Implements hook_menu_alter().
  139. */
  140. -function i18n_access_menu_alter(&$items) {
  141. +
  142. +//make function name i18n_access_node_menu_alter
  143. +function i18n_access_node_menu_alter(&$items) {
  144. +
  145. + // 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?
  146. // Replace the translation overview page since we can't hook it.
  147. $items['node/%node/translate']['page callback'] = 'i18n_access_translation_node_overview';
  148. +
  149. }
  150. function i18n_access_translation_node_overview($node) {
  151. include_once DRUPAL_ROOT . '/includes/language.inc';
  152. - if (!empty($node->tnid)) {
  153. - // Already part of a set, grab that set.
  154. - $tnid = $node->tnid;
  155. - $translations = translation_node_get_translations($node->tnid);
  156. - }
  157. - else {
  158. - // We have no translation source nid, this could be a new set, emulate that.
  159. - $tnid = $node->nid;
  160. - $translations = array($node->language => $node);
  161. + // include functions from i18n_node.pages.inc
  162. + include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'i18n_node') . '/i18n_node.pages.inc';
  163. +
  164. + // this is the part where this thing sorts out how to build a list of existing translations for this node
  165. + // 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]
  166. + $available_translations = $node->translations->data;
  167. +
  168. + // 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
  169. + foreach ($available_translations as $key => $value) {
  170. + $translations[$key] = $node;
  171. }
  172. $type = variable_get('translation_language_type', LANGUAGE_TYPE_INTERFACE);
  173. +
  174. $header = array(t('Language'), t('Title'), t('Status'), t('Operations'));
  175. //added from i18n/i18n_node/i18n_node.pages.inc function
  176. @@ -240,9 +276,9 @@ function i18n_access_translation_node_overview($node) {
  177. $perms = i18n_access_load_permissions($account->uid);
  178. //end
  179. -
  180. // Modes have different allowed languages
  181. foreach (i18n_node_language_list($node) as $langcode => $language_name) {
  182. +
  183. if ($langcode == LANGUAGE_NONE) {
  184. // Never show language neutral on the overview.
  185. continue;
  186. @@ -253,16 +289,24 @@ function i18n_access_translation_node_overview($node) {
  187. // We load the full node to check whether the user can edit it.
  188. $translation_node = node_load($translations[$langcode]->nid);
  189. $path = 'node/' . $translation_node->nid;
  190. - $title = i18n_node_translation_link($translation_node->title, $path, $langcode);
  191. - if (node_access('update', $translation_node)) {
  192. +
  193. + // Account for title field module:
  194. + if (isset($translation_node->title_field) && isset($translation_node->title_field[$langcode])) {
  195. + $title = i18n_node_translation_link($translation_node->title_field[$langcode][0]['value'], $path, $langcode);
  196. + }
  197. + else {
  198. + $title = i18n_node_translation_link($translation_node->title, $path, $langcode);
  199. + }
  200. +
  201. + if (i18n_access_node_access($translation_node, 'update', $user, $langcode)) {
  202. $text = t('edit');
  203. $path = 'node/' . $translation_node->nid . '/edit';
  204. $options[] = i18n_node_translation_link($text, $path, $langcode);
  205. }
  206. $status = $translation_node->status ? t('Published') : t('Not published');
  207. - $status .= $translation_node->translate ? ' - <span class="marker">' . t('outdated') . '</span>' : '';
  208. + $status .= $translation_node->translate ? ' - ' . t('outdated') . '' : '';
  209. if ($translation_node->nid == $tnid) {
  210. - $language_name = t('<strong>@language_name</strong> (source)', array('@language_name' => $language_name));
  211. + $language_name = t('@language_name (source)', array('@language_name' => $language_name));
  212. }
  213. }
  214. else {
  215. @@ -316,6 +360,52 @@ function i18n_access_menu() {
  216. }
  217. /**
  218. + * Node-specific menu alterations.
  219. + */
  220. +function i18n_access_menu_alter(&$items, $backup) {
  221. + if (isset($backup['node'])) {
  222. + $item = $backup['node'];
  223. + // Preserve the menu router item defined by other modules.
  224. + $callback['page callback'] = $item['page callback'];
  225. + $callback['file'] = $item['file'];
  226. + $callback['module'] = $item['module'];
  227. + $access_arguments = array_merge(array(1, $item['access callback']), $item['access arguments']);
  228. + }
  229. + else {
  230. + $access_arguments = array(1);
  231. + }
  232. +
  233. + // Point the 'translate' tab to point to the i18n_access version of the translation overview page
  234. + $items['node/%node/translate']['page callback'] = 'i18n_access_translation_node_overview';
  235. +
  236. + // There are 3 page arguments for the entity translation overview, only one for i18n_access:
  237. + $items['node/%node/translate']['page arguments'] = array(1);
  238. +
  239. + // Pass in the i18n_access permissions
  240. + $items['node/%node/translate']['access arguments'] = $access_arguments;
  241. +
  242. + // Point to i18n_access's include for the callback
  243. + $items['node/%node/translate']['file'] = 'i18n_access.module';
  244. +
  245. + // Point to i18n_access module
  246. + $items['node/%node/translate']['module'] = 'i18n_access';
  247. +}
  248. +
  249. +/**
  250. + * Implements hook_module_implements_alter().
  251. + */
  252. +function i18n_access_module_implements_alter(&$implementations, $hook) {
  253. + switch ($hook) {
  254. + case 'menu_alter':
  255. + // Move our hook_menu_alter implementation to the end of the list.
  256. + $group = $implementations['i18n_access'];
  257. + unset($implementations['i18n_access']);
  258. + $implementations['i18n_access'] = $group;
  259. + break;
  260. + }
  261. +}
  262. +
  263. +/**
  264. * Admin settings form
  265. */
  266. function i18n_access_admin_settings() {
  267. @@ -330,4 +420,4 @@ function i18n_access_admin_settings() {
  268. );
  269. return system_settings_form($form);
  270. -}
  271. \ No newline at end of file
  272. +}