tmgmt_file.ui.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * @file
  4. * Please supply a file description.
  5. */
  6. /**
  7. * File translator plugin controller.
  8. */
  9. class TMGMTFileTranslatorUIController extends TMGMTDefaultTranslatorUIController {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function pluginSettingsForm($form, &$form_state, TMGMTTranslator $translator, $busy = FALSE) {
  14. $form['export_format'] = array(
  15. '#type' => 'radios',
  16. '#title' => t('Export to'),
  17. '#options' => tmgmt_file_format_plugin_labels(),
  18. '#default_value' => $translator->getSetting('export_format'),
  19. '#description' => t('Please select the format you want to export data.'),
  20. );
  21. $form['xliff_cdata'] = array(
  22. '#type' => 'checkbox',
  23. '#title' => t('XLIFF CDATA'),
  24. '#description' => t('Check to use CDATA for import/export.'),
  25. '#default_value' => $translator->getSetting('xliff_cdata'),
  26. );
  27. $form['xliff_processing'] = array(
  28. '#type' => 'checkbox',
  29. '#title' => t('Extended XLIFF processing'),
  30. '#description' => t('Check to further process content semantics and mask HTML tags instead just escaping it.'),
  31. '#default_value' => $translator->getSetting('xliff_processing'),
  32. );
  33. $form['xliff_message'] = array(
  34. '#type' => 'item',
  35. '#markup' => t('By selecting CDATA option, XLIFF processing will be ignored.'),
  36. '#prefix' => '<div class="messages warning">',
  37. '#suffix' => '</div>',
  38. );
  39. $form['allow_override'] = array(
  40. '#type' => 'checkbox',
  41. '#title' => t('Allow to override the format per job'),
  42. '#default_value' => $translator->getSetting('allow_override'),
  43. );
  44. // Any visible, writeable wrapper can potentially be used for the files
  45. // directory, including a remote file system that integrates with a CDN.
  46. foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $info) {
  47. $options[$scheme] = check_plain($info['description']);
  48. }
  49. if (!empty($options)) {
  50. $form['scheme'] = array(
  51. '#type' => 'radios',
  52. '#title' => t('Download method'),
  53. '#default_value' => $translator->getSetting('scheme'),
  54. '#options' => $options,
  55. '#description' => t('Choose the location where exported files should be stored. The usage of a protected location (e.g. private://) is recommended to prevent unauthorized access.'),
  56. );
  57. }
  58. return parent::pluginSettingsForm($form, $form_state, $translator);
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. public function checkoutSettingsForm($form, &$form_state, TMGMTJob $job) {
  64. if ($job->getTranslator()->getSetting('allow_override')) {
  65. $form['export_format'] = array(
  66. '#type' => 'radios',
  67. '#title' => t('Export to'),
  68. '#options' => tmgmt_file_format_plugin_labels(),
  69. '#default_value' => $job->getTranslator()->getSetting('export_format'),
  70. '#description' => t('Please select the format you want to export data.'),
  71. );
  72. }
  73. return parent::checkoutSettingsForm($form, $form_state, $job);
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function checkoutInfo(TMGMTJob $job) {
  79. // If the job is finished, it's not possible to import translations anymore.
  80. if ($job->isFinished()) {
  81. return parent::checkoutInfo($job);
  82. }
  83. $form = array(
  84. '#type' => 'fieldset',
  85. '#title' => t('Import translated file'),
  86. );
  87. $supported_formats = array_keys(tmgmt_file_format_plugin_info());
  88. $form['file'] = array(
  89. '#type' => 'file',
  90. '#title' => t('File file'),
  91. '#size' => 50,
  92. '#description' => t('Supported formats: @formats.', array('@formats' => implode(', ', $supported_formats))),
  93. );
  94. $form['submit'] = array(
  95. '#type' => 'submit',
  96. '#value' => t('Import'),
  97. '#submit' => array('tmgmt_file_import_form_submit'),
  98. );
  99. return $this->checkoutInfoWrapper($job, $form);
  100. }
  101. }