tmgmt.ui.translator.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Default ui controller class for translator plugins.
  4. *
  5. * @ingroup tmgmt_translator
  6. */
  7. class TMGMTDefaultTranslatorUIController extends TMGMTPluginBase implements TMGMTTranslatorUIControllerInterface {
  8. /**
  9. * {@inheritdoc}
  10. */
  11. public function pluginSettingsForm($form, &$form_state, TMGMTTranslator $translator, $busy = FALSE) {
  12. if (!empty($translator->plugin)) {
  13. $controller = tmgmt_translator_plugin_controller($translator->plugin);
  14. }
  15. // If current translator is configured to provide remote language mapping
  16. // provide the form to configure mappings, unless it does not exists yet.
  17. if (!empty($controller) && tmgmt_provide_remote_languages_mappings($translator)) {
  18. $form['remote_languages_mappings'] = array(
  19. '#tree' => TRUE,
  20. '#type' => 'fieldset',
  21. '#title' => t('Remote languages mappings'),
  22. '#description' => t('Here you can specify mappings of your local language codes to the translator language codes.'),
  23. '#collapsible' => TRUE,
  24. '#collapsed' => TRUE,
  25. );
  26. $options = array();
  27. foreach ($controller->getSupportedRemoteLanguages($translator) as $language) {
  28. $options[$language] = $language;
  29. }
  30. ksort($options);
  31. foreach ($controller->getRemoteLanguagesMappings($translator) as $local_language => $remote_language) {
  32. $form['remote_languages_mappings'][$local_language] = array(
  33. '#type' => 'textfield',
  34. '#title' => tmgmt_language_label($local_language) . ' (' . $local_language . ')',
  35. '#default_value' => $remote_language,
  36. '#size' => 6,
  37. );
  38. if (!empty($options)) {
  39. $form['remote_languages_mappings'][$local_language]['#type'] = 'select';
  40. $form['remote_languages_mappings'][$local_language]['#options'] = $options;
  41. $form['remote_languages_mappings'][$local_language]['#empty_option'] = ' - ';
  42. unset($form['remote_languages_mappings'][$local_language]['#size']);
  43. }
  44. }
  45. }
  46. if (!element_children($form)) {
  47. $form['#description'] = t("The @plugin plugin doesn't provide any settings.", array('@plugin' => $this->pluginInfo['label']));
  48. }
  49. return $form;
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function checkoutSettingsForm($form, &$form_state, TMGMTJob $job) {
  55. if (!element_children($form)) {
  56. $form['#description'] = t("The @translator translator doesn't provide any checkout settings.", array('@translator' => $job->getTranslator()->label()));
  57. }
  58. return $form;
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. public function checkoutInfo(TMGMTJob $job) {
  64. return array();
  65. }
  66. /**
  67. * Provides a simple wrapper for the checkout info fieldset.
  68. *
  69. * @param TMGMTJob $job
  70. * Translation job object.
  71. * @param $form
  72. * Partial form structure to be wrapped in the fieldset.
  73. *
  74. * @return
  75. * The provided form structure wrapped in a collapsed fieldset.
  76. */
  77. public function checkoutInfoWrapper(TMGMTJob $job, $form) {
  78. $label = $job->getTranslator()->label();
  79. $form += array(
  80. '#title' => t('@translator translation job information', array('@translator' => $label)),
  81. '#type' => 'fieldset',
  82. '#collapsible' => TRUE,
  83. );
  84. return $form;
  85. }
  86. /**
  87. * {@inheritdoc}
  88. */
  89. public function reviewForm($form, &$form_state, TMGMTJobItem $item) {
  90. return $form;
  91. }
  92. /**
  93. * {@inheritdoc}
  94. */
  95. public function reviewDataItemElement($form, &$form_state, $data_item_key, $parent_key, array $data_item, TMGMTJobItem $item) {
  96. return $form;
  97. }
  98. /**
  99. * {@inheritdoc}
  100. */
  101. public function reviewFormValidate($form, &$form_state, TMGMTJobItem $item) {
  102. // Nothing to do here by default.
  103. }
  104. /**
  105. * {@inheritdoc}
  106. */
  107. public function reviewFormSubmit($form, &$form_state, TMGMTJobItem $item) {
  108. // Nothing to do here by default.
  109. }
  110. }