class SmartlingTranslatorUi in TMGMT Translator Smartling 8
Same name and namespace in other branches
- 8.4 src/SmartlingTranslatorUi.php \Drupal\tmgmt_smartling\SmartlingTranslatorUi
- 8.2 src/SmartlingTranslatorUi.php \Drupal\tmgmt_smartling\SmartlingTranslatorUi
- 8.3 src/SmartlingTranslatorUi.php \Drupal\tmgmt_smartling\SmartlingTranslatorUi
Smartling translator UI.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\tmgmt\TranslatorPluginUiBase implements TranslatorPluginUiInterface
- class \Drupal\tmgmt_smartling\SmartlingTranslatorUi
- class \Drupal\tmgmt\TranslatorPluginUiBase implements TranslatorPluginUiInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of SmartlingTranslatorUi
File
- src/
SmartlingTranslatorUi.php, line 18 - Contains \Drupal\tmgmt_smartling\SmartlingTranslatorUi.
Namespace
Drupal\tmgmt_smartlingView source
class SmartlingTranslatorUi extends TranslatorPluginUiBase {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
/** @var \Drupal\tmgmt\TranslatorInterface $translator */
$translator = $form_state
->getFormObject()
->getEntity();
$form['api_url'] = [
'#type' => 'textfield',
'#title' => t('API URL'),
'#default_value' => $translator
->getSetting('api_url'),
'#size' => 25,
'#maxlength' => 255,
'#required' => TRUE,
'#description' => t('Set api url. Default: @api_url', [
'@api_url' => $translator
->getSetting('api_url'),
]),
];
$form['project_id'] = [
'#type' => 'textfield',
'#title' => t('Project Id'),
'#default_value' => $translator
->getSetting('project_id'),
'#size' => 25,
'#maxlength' => 25,
'#required' => TRUE,
];
$form['key'] = [
'#type' => 'textfield',
'#title' => t('Key'),
'#default_value' => $translator
->getSetting('key'),
'#size' => 40,
'#maxlength' => 40,
'#required' => TRUE,
];
$form['orgID'] = [
'#type' => 'textfield',
'#title' => t('orgID'),
'#size' => 40,
'#maxlength' => 40,
'#default_value' => $translator
->getSetting('orgID'),
'#required' => FALSE,
];
$form['contextUsername'] = [
'#type' => 'textfield',
'#title' => t('Username for context retrieval'),
'#size' => 40,
'#maxlength' => 40,
'#default_value' => $translator
->getSetting('contextUsername'),
'#required' => FALSE,
];
$form['context_silent_user_switching'] = [
'#type' => 'checkbox',
'#title' => t('Context silent user authentication'),
'#description' => t('If checked, Smartling won\'t trigger hook_login and hook_logout during user authentication for retrieving context.'),
'#default_value' => $translator
->getSetting('context_silent_user_switching'),
'#required' => FALSE,
];
$form['context_skip_host_verifying'] = [
'#type' => 'checkbox',
'#title' => t('Skip host verification'),
'#description' => t('If checked, curl won\'t verify host during retrieving context (CURLOPT_SSL_VERIFYHOST = 0). Use only for developing and testing purposes on NON PRODUCTION environments.'),
'#default_value' => $translator
->getSetting('context_skip_host_verifying'),
'#required' => FALSE,
];
$form['retrieval_type'] = [
'#type' => 'select',
'#title' => t('The desired format for download'),
'#default_value' => $translator
->getSetting('retrieval_type'),
'#options' => [
'pending' => t('Smartling returns any translations (including non-published translations)'),
'published' => t('Smartling returns only published/pre-published translations'),
'pseudo' => t('Smartling returns a modified version of the original text'),
],
'#required' => FALSE,
];
$form['auto_authorize_locales'] = [
'#type' => 'checkbox',
'#title' => t('Automatically authorize content for translation in Smartling'),
// @todo Add description to display full URL.
'#default_value' => $translator
->getSetting('auto_authorize_locales'),
'#required' => FALSE,
];
$form['callback_url_use'] = [
'#type' => 'checkbox',
'#title' => t('Use Smartling callback: /smartling/callback/%cron_key'),
// @todo Add description to display full URL.
'#default_value' => $translator
->getSetting('callback_url_use'),
'#required' => FALSE,
];
// Any visible, writable wrapper can potentially be used for the files
// directory, including a remote file system that integrates with a CDN.
foreach (\Drupal::service('stream_wrapper_manager')
->getDescriptions(StreamWrapperInterface::WRITE_VISIBLE) as $scheme => $description) {
$options[$scheme] = $description;
}
if (!empty($options)) {
$form['scheme'] = [
'#type' => 'radios',
'#title' => t('Download method'),
'#default_value' => $translator
->getSetting('scheme'),
'#options' => $options,
'#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.'),
];
}
$form['custom_regexp_placeholder'] = [
'#type' => 'textfield',
'#title' => t('Custom placeholder (regular expression)'),
'#description' => t('The content matching this regular expression will not be editable by translators in Smartling.'),
'#size' => 40,
'#maxlength' => 80,
'#default_value' => $translator
->getSetting('custom_regexp_placeholder'),
'#required' => FALSE,
];
$form['export_format'] = [
'#type' => 'select',
'#title' => t('File type'),
'#description' => t('The file type format that is used to upload/download from Smartling'),
'#default_value' => $translator
->getSetting('export_format'),
'#options' => [
'html' => t('HTML'),
'xlf' => t('XLIFF'),
'xml' => t('XML'),
],
'#required' => FALSE,
];
// TODO: identical filename task.
// $form['identical_file_name'] = [
// '#type' => 'checkbox',
// '#title' => t('Use identical file names for jobs that contain identical content'),
// '#description' => t('Generated file will have identical name for jobs that have identical content.'),
// '#default_value' => $translator->getSetting('identical_file_name'),
// '#required' => FALSE,
// ];
$basic_auth_defaults = $translator
->getSetting('basic_auth');
$form['enable_basic_auth'] = [
'#type' => 'checkbox',
'#title' => t('Enable basic auth for context.'),
'#default_value' => $translator
->getSetting('enable_basic_auth'),
];
$form['basic_auth'] = [
'#type' => 'details',
'#title' => t('Basic auth'),
'#open' => TRUE,
'#states' => [
'visible' => [
'input[name="settings[enable_basic_auth]"]' => [
'checked' => TRUE,
],
],
],
];
$form['basic_auth']['login'] = [
'#type' => 'textfield',
'#title' => t('Login'),
'#default_value' => $basic_auth_defaults['login'],
'#states' => [
'required' => [
'input[name="settings[enable_basic_auth]"]' => [
'checked' => TRUE,
],
],
],
];
$form['basic_auth']['password'] = [
'#type' => 'textfield',
'#title' => t('Password'),
'#default_value' => $basic_auth_defaults['password'],
'#states' => [
'required' => [
'input[name="settings[enable_basic_auth]"]' => [
'checked' => TRUE,
],
],
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::validateConfigurationForm($form, $form_state);
/** @var \Drupal\tmgmt\TranslatorInterface $translator */
$translator = $form_state
->getFormObject()
->getEntity();
$supported_remote_languages = $translator
->getPlugin()
->getSupportedRemoteLanguages($translator);
if (empty($supported_remote_languages)) {
$form_state
->setErrorByName('settings][project_id', t('The "Project ID", the "Client key" or both are not correct.'));
$form_state
->setErrorByName('settings][key', t('The "Project ID", the "Client key" or both are not correct.'));
}
if ($translator
->getSetting('enable_basic_auth')) {
$auth_settings = $translator
->getSetting('basic_auth');
if (empty($auth_settings['login']) || empty($auth_settings['password'])) {
$form_state
->setErrorByName('settings][basic_auth', t('Please fill in both login and password (HTTP basic authentication credentials).'));
}
}
}
/**
* {@inheritdoc}
*/
public function checkoutInfo(JobInterface $job) {
// If the job is finished, it's not possible to import translations anymore.
if ($job
->isFinished()) {
return parent::checkoutInfo($job);
}
$output = [];
try {
$output = array(
'#type' => 'fieldset',
'#title' => t('Import translated file'),
);
$output['submit'] = array(
'#type' => 'submit',
'#value' => t('Download'),
'#submit' => [
'tmgmt_smartling_download_file_submit',
],
);
$output = $this
->checkoutInfoWrapper($job, $output);
} catch (\Exception $e) {
}
return $output;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
SmartlingTranslatorUi:: |
public | function |
Form constructor. Overrides TranslatorPluginUiBase:: |
|
SmartlingTranslatorUi:: |
public | function |
Retrieves information about a translation job. Overrides TranslatorPluginUiBase:: |
|
SmartlingTranslatorUi:: |
public | function |
Form validation handler. Overrides TranslatorPluginUiBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TranslatorPluginUiBase:: |
public | function | Adds a "Connect" button to a form. | |
TranslatorPluginUiBase:: |
public | function | Provides a simple wrapper for the checkout info fieldset. | |
TranslatorPluginUiBase:: |
public | function |
Form callback for the checkout settings form. Overrides TranslatorPluginUiInterface:: |
3 |
TranslatorPluginUiBase:: |
public | function |
Form callback for the data item element form. Overrides TranslatorPluginUiInterface:: |
1 |
TranslatorPluginUiBase:: |
public | function |
Form callback for the job item review form. Overrides TranslatorPluginUiInterface:: |
|
TranslatorPluginUiBase:: |
public | function |
Submit callback for the job item review form. Overrides TranslatorPluginUiInterface:: |
|
TranslatorPluginUiBase:: |
public | function |
Validation callback for the job item review form. Overrides TranslatorPluginUiInterface:: |
|
TranslatorPluginUiBase:: |
public | function |
Form submission handler. Overrides TranslatorPluginUiInterface:: |
|
TranslatorPluginUiBase:: |
public | function | Handles submit call of "Connect" button. |