tmgmt_node_ui.module 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * @file
  4. * Main module file for the translation management node source plugin user
  5. * interface.
  6. */
  7. /**
  8. * Implements hook_page_alter().
  9. */
  10. function tmgmt_node_ui_page_alter(&$page) {
  11. // Translation tabs for nodes.
  12. if (($node = menu_get_object()) && entity_access('create', 'tmgmt_job')) {
  13. if (isset($page['content']['system_main']['translation_node_overview'])) {
  14. module_load_include('inc', 'tmgmt_node_ui', 'tmgmt_node_ui.pages');
  15. $page['content']['system_main']['translation_node_overview'] = drupal_get_form('tmgmt_node_ui_node_form', $node, $page['content']['system_main']['translation_node_overview']);
  16. }
  17. // Support the context module: when context is used for placing the
  18. // system_main block, then block contents appear nested one level deeper
  19. // under another 'content' key.
  20. elseif (isset($page['content']['system_main']['content']['translation_node_overview'])) {
  21. module_load_include('inc', 'tmgmt_node_ui', 'tmgmt_node_ui.pages');
  22. $page['content']['system_main']['content']['translation_node_overview'] = drupal_get_form('tmgmt_node_ui_node_form', $node, $page['content']['system_main']['content']['translation_node_overview']);
  23. }
  24. }
  25. }
  26. /**
  27. * Implements hook_action_info().
  28. */
  29. function tmgmt_node_ui_action_info() {
  30. return array(
  31. 'tmgmt_node_ui_checkout_multiple_action' => array(
  32. 'type' => 'node',
  33. 'label' => t('Request translations'),
  34. 'configurable' => false,
  35. 'aggregate' => true
  36. )
  37. );
  38. }
  39. /**
  40. * Action to do multistep checkout for translations.
  41. *
  42. * @param array $nodes
  43. * Array of Drupal nodes.
  44. * @param $info
  45. * Action info - not used.
  46. *
  47. */
  48. function tmgmt_node_ui_checkout_multiple_action($nodes, $info) {
  49. $jobs = array();
  50. $source_lang_registry = array();
  51. // Loop through entities and create individual jobs for each source language.
  52. foreach ($nodes as $node) {
  53. try {
  54. // For given source lang no job exists yet.
  55. if (!isset($source_lang_registry[$node->language])) {
  56. // Create new job.
  57. $job = tmgmt_job_create($node->language, NULL, $GLOBALS['user']->uid);
  58. // Add initial job item.
  59. $job->addItem('node', 'node', $node->nid);
  60. // Add job identifier into registry
  61. $source_lang_registry[$node->language] = $job->tjid;
  62. // Add newly created job into jobs queue.
  63. $jobs[$job->tjid] = $job;
  64. }
  65. // We have a job for given source lang, so just add new job item for the
  66. // existing job.
  67. else {
  68. $jobs[$source_lang_registry[$node->language]]->addItem('node', 'node', $node->nid);
  69. }
  70. }
  71. catch (TMGMTException $e) {
  72. watchdog_exception('tmgmt', $e);
  73. drupal_set_message(t('Unable to add job item for node %name. Make sure the source content is not empty.', array('%name' => $node->title)), 'error');
  74. }
  75. }
  76. // If necessary, do a redirect.
  77. $redirects = tmgmt_ui_job_checkout_multiple($jobs);
  78. if ($redirects) {
  79. tmgmt_ui_redirect_queue_set($redirects, current_path());
  80. drupal_set_message(format_plural(count($redirects), t('One job needs to be checked out.'), t('@count jobs need to be checked out.')));
  81. drupal_goto(tmgmt_ui_redirect_queue_dequeue());
  82. }
  83. }