entity_translation_tabs.module 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @file entity_translation_tabs.module
  4. * This module gives you a tab for each language on entity translation nodes.
  5. */
  6. /**
  7. * Implements hook_menu_alter().
  8. */
  9. function entity_translation_tabs_menu_alter(&$items) {
  10. $items['node/%node/edit']['weight'] = 3;
  11. $items['node/%node/edit']['title'] = t('Source');
  12. // It would be nice to hide the translate tab when it is no longer needed
  13. // but this causes problems with the entity_translation module.
  14. }
  15. /**
  16. * Implements hook_menu().
  17. */
  18. function entity_translation_tabs_menu() {
  19. $languages = language_list('enabled');
  20. // Eventually it would be nice to replace this series of menu entries with
  21. // the same code as the entity_translation module's hook_menu code to allow
  22. // us to show the tabs in taxonomy, user, and other types of entities.
  23. foreach ($languages[1] as $key => $value) {
  24. $items['node/%node/' . "$key"] = array(
  25. 'title' => 'Edit' . ' [' . $value->name . ']',
  26. 'page callback' => 'entity_translation_tabs_switcher',
  27. 'page arguments' => array(1, 2),
  28. 'access callback' => 'node_access',
  29. 'access arguments' => array('update', 1),
  30. 'weight' => 0,
  31. 'type' => MENU_LOCAL_TASK,
  32. 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
  33. );
  34. }
  35. return $items;
  36. }
  37. /**
  38. * Redirection logic to determine where the tabs will take you.
  39. */
  40. function entity_translation_tabs_switcher($node, $lang) {
  41. // This switcher currently does a drupal_goto for each appropriate case, but
  42. // the intended functionality is to load the entity translation form directly
  43. // on each applicable tab. It will require loading the appropraite inc files
  44. // and then to load the entity_translation_edit_form with all the parameters.
  45. $nid = $node->nid;
  46. $und = FALSE;
  47. $result = db_query(
  48. "SELECT language, source FROM {entity_translation} WHERE entity_id=:eid",
  49. array(
  50. ':eid' => $nid,
  51. ));
  52. foreach ($result as $record) {
  53. // Source is not set, therefore it is source.
  54. if (sizeof($record->source) == 1) {
  55. $source = $record->language;
  56. }
  57. // Source is undefined, therefore edit original.
  58. if ($record->language == 'und') {
  59. $und = TRUE;
  60. }
  61. // Translation exists, let's go there.
  62. if ($record->language == $lang) {
  63. drupal_goto('node/' . $nid . '/edit/' . $lang);
  64. }
  65. }
  66. if ($und != TRUE) {
  67. drupal_set_message(t('This is a new translation, please translate it now.'), 'warning');
  68. drupal_goto('node/' . $nid . '/edit/add/' . $source . "/" . $lang);
  69. }
  70. else {
  71. drupal_set_message(t('This content is set to display on all languages.
  72. Set the language of this page to make it translatable.'), 'warning');
  73. drupal_goto('node/' . $nid . '/edit');
  74. }
  75. return;
  76. }