node.translation_table.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * @file
  4. * Provide translation table functionality for the node module.
  5. */
  6. /**
  7. * Implementation of hook_translation_table_data().
  8. */
  9. function node_translation_table_data() {
  10. $items['nodetype'] = array(
  11. 'title' => 'Content type',
  12. 'description' => 'Edit content type translations',
  13. 'form' => 'node_translation_table_nodetype_form',
  14. 'file' => 'modules/node.translation_table.inc',
  15. );
  16. return $items;
  17. }
  18. /**
  19. * Menu callback; Admin form for node type translation.
  20. */
  21. function node_translation_table_nodetype_form($form, &$form_state) {
  22. $languages_selected = isset($_SESSION['translation_table']['languages_selected']) ? $_SESSION['translation_table']['languages_selected'] : locale_language_list('name', FALSE);
  23. $nodetype = isset($_SESSION['translation_table']['nodetype']) ? $_SESSION['translation_table']['nodetype'] : 0;
  24. $form['filter'] = node_translation_table_nodetype_filter($languages_selected, $nodetype);
  25. $form['filtered_form'] = node_translation_table_nodetype_filtered_form($languages_selected, $nodetype);
  26. $form['#submit'][] = 'node_translation_table_nodetype_form_submit';
  27. $form['#submit'][] = 'translation_table_submit_translations';
  28. return $form;
  29. }
  30. /**
  31. * Node type filter.
  32. */
  33. function node_translation_table_nodetype_filter($languages_selected, $nodetype) {
  34. $form['languages_selected'] = array(
  35. '#type' => 'select',
  36. '#title' => t('Languages'),
  37. '#description' => t('Select the languages to display.'),
  38. '#options' => locale_language_list('name', TRUE),
  39. '#default_value' => array_keys($languages_selected),
  40. '#multiple' => TRUE,
  41. );
  42. $form['nodetype'] = array(
  43. '#type' => 'select',
  44. '#title' => t('Content type'),
  45. '#description' => t('Select the content types to display.'),
  46. '#options' => array_merge(array( 0 => t('- All -')), node_type_get_names()),
  47. '#default_value' => $nodetype,
  48. );
  49. $form['filter'] = array(
  50. '#type' => 'submit',
  51. '#value' => t('Filter'),
  52. );
  53. $form['#theme'] = 'translation_table_filter';
  54. return $form;
  55. }
  56. /**
  57. * Form for node type translation.
  58. * Note: If the node type is not in the locales_source table, then it won't be
  59. * displayed.
  60. *
  61. * @param $languages
  62. * languages to translate to
  63. * @param $nodetype
  64. * 0: show all
  65. * else: filter by node type
  66. */
  67. function node_translation_table_nodetype_filtered_form($languages, $nodetype) {
  68. $header = _translation_table_get_header($languages);
  69. switch ($nodetype) {
  70. case '0':
  71. $query = db_select('locales_source', 'ls');
  72. $query->fields('ls', array('lid', 'source', 'location'))
  73. ->extend('PagerDefault')
  74. ->extend('TableSort')
  75. ->condition('ls.textgroup', 'node')
  76. ->orderByHeader($header)
  77. ->limit(50);
  78. $result = $query->execute();
  79. break;
  80. default:
  81. $query = db_select('locales_source', 'ls');
  82. $query->fields('ls', array('lid', 'source', 'location'))
  83. ->extend('PagerDefault')
  84. ->extend('TableSort')
  85. ->condition('ls.textgroup', 'taxonomy')
  86. ->condition('ls.location', 'node:type: ' . check_plain($nodetype) . ' %', 'LIKE')
  87. ->orderByHeader($header)
  88. ->limit(50);
  89. $result = $query->execute();
  90. break;
  91. }
  92. $form['strings']['#tree'] = TRUE;
  93. $form['#cache'] = FALSE;
  94. $form['header'] = array(
  95. '#type' => 'value',
  96. '#value' => $header,
  97. );
  98. while ($source = $result->fetch()) {
  99. if (strlen(trim($source->source)) > 0) {
  100. $form['strings'][$source->lid] = _translation_table_row($source, $languages);
  101. }
  102. }
  103. $form['languages'] = array(
  104. '#type' => 'value',
  105. '#value' => $languages,
  106. );
  107. $form['submit'] = array(
  108. '#type' => 'submit',
  109. '#value' => t('Save'),
  110. );
  111. $form['pager'] = array('#markup' => theme('pager'));
  112. $form['#theme'] = 'translation_table';
  113. return $form;
  114. }
  115. /**
  116. * Submit handler for the node type translation form.
  117. */
  118. function node_translation_table_nodetype_form_submit($form, &$form_state) {
  119. switch ($form_state['clicked_button']['#id']) {
  120. case 'edit-filter':
  121. case 'edit-submit':
  122. $_SESSION['translation_table']['nodetype'] = $form_state['values']['nodetype'];
  123. $_SESSION['translation_table']['languages_selected'] = array_intersect_key(locale_language_list('name', TRUE), $form_state['values']['languages_selected']);
  124. break;
  125. }
  126. }