You are here

public function GlobalLinkTranslatorUi::buildConfigurationForm in GlobalLink Connect for Drupal 8

Same name and namespace in other branches
  1. 8.2 src/GlobalLinkTranslatorUi.php \Drupal\globallink\GlobalLinkTranslatorUi::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/GlobalLinkTranslatorUi.php, line 40
Contains Drupal\globallink\GlobalLinkTranslatorUi.

Class

GlobalLinkTranslatorUi
GlobalLink translator UI.

Namespace

Drupal\globallink

Code

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['pd_url'] = [
    '#type' => 'url',
    '#title' => t('GlobalLink api url'),
    '#required' => TRUE,
    '#default_value' => $translator
      ->getSetting('pd_url'),
    '#description' => t('Add the api url provided by translations.com'),
  ];
  $form['pd_username'] = [
    '#type' => 'textfield',
    '#title' => t('GlobalLink username'),
    '#required' => TRUE,
    '#default_value' => $translator
      ->getSetting('pd_username'),
    '#description' => t('Add the username provided by translations.com'),
  ];
  $form['pd_password'] = [
    '#type' => 'password',
    '#title' => t('GlobalLink password'),
    '#required' => TRUE,
    '#default_value' => $translator
      ->getSetting('pd_password'),
    '#description' => t('Add the password provided by translations.com'),
  ];
  $form['pd_projectid'] = [
    '#type' => 'textfield',
    '#title' => t('GlobalLink project id'),
    '#required' => TRUE,
    '#default_value' => $translator
      ->getSetting('pd_projectid'),
    '#description' => t('Add the project id provided by translations.com'),
  ];
  $form['pd_submissionprefix'] = [
    '#type' => 'textfield',
    '#title' => t('GlobalLink submission prefix'),
    '#required' => TRUE,
    '#default_value' => $translator
      ->getSetting('pd_submissionprefix'),
    '#description' => t('Choose a prefix'),
  ];
  $form['pd_classifier'] = [
    '#type' => 'textfield',
    '#title' => t('GlobalLink classifier'),
    '#required' => TRUE,
    '#default_value' => $translator
      ->getSetting('pd_classifier'),
    '#description' => t('Add a classifier'),
  ];
  $form['pd_notify_emails'] = [
    '#type' => 'textfield',
    '#title' => t('Emails for notification'),
    '#default_value' => $translator
      ->getSetting('pd_notify_emails'),
    '#description' => t('A space separated list of emails to notify. Leave blank for no notifications'),
  ];
  $form['pd_combine'] = [
    '#type' => 'checkbox',
    '#title' => t('Combine all items into a single document'),
    '#default_value' => $translator
      ->getSetting('pd_combine'),
    '#description' => t('If checked, a single document will be sent for a translation job, otherwise a separate document within a single submission will be created for each job item.'),
  ];
  $form['pd_due_date_offset'] = [
    '#type' => 'textfield',
    '#title' => t('Default due date offset in working days'),
    '#default_value' => $translator
      ->getSetting('pd_due_date_offset') ?: 3,
    '#description' => t('Controls the default due date, which then by default uses the configured amount of working days in the future.'),
  ];
  $form['pd_notify_level'] = [
    '#type' => 'checkboxes',
    '#title' => t('Email notification levels'),
    '#options' => [
      GlobalLinkTranslator::MSG_STATUS => t('Status'),
      GlobalLinkTranslator::MSG_DEBUG => t('Debug'),
      GlobalLinkTranslator::MSG_WARNING => t('Warning'),
      GlobalLinkTranslator::MSG_ERROR => t('Error'),
    ],
    '#default_value' => (array) $translator
      ->getSetting('pd_notify_level'),
    '#description' => t('Select which tmgmt message types to send via email. Selecting all can result in a high volume of emails being sent.'),
  ];
  return $form;
}