public function SmartlingTranslatorUi::buildConfigurationForm in TMGMT Translator Smartling 8
Same name and namespace in other branches
- 8.4 src/SmartlingTranslatorUi.php \Drupal\tmgmt_smartling\SmartlingTranslatorUi::buildConfigurationForm()
- 8.2 src/SmartlingTranslatorUi.php \Drupal\tmgmt_smartling\SmartlingTranslatorUi::buildConfigurationForm()
- 8.3 src/SmartlingTranslatorUi.php \Drupal\tmgmt_smartling\SmartlingTranslatorUi::buildConfigurationForm()
Form constructor.
Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.
Parameters
array $form: An associative array containing the initial structure of the plugin form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().
Return value
array The form structure.
Overrides TranslatorPluginUiBase::buildConfigurationForm
File
- src/
SmartlingTranslatorUi.php, line 23 - Contains \Drupal\tmgmt_smartling\SmartlingTranslatorUi.
Class
- SmartlingTranslatorUi
- Smartling translator UI.
Namespace
Drupal\tmgmt_smartlingCode
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;
}