You are here

public function SmartlingTranslatorUi::checkoutSettingsForm in TMGMT Translator Smartling 8.3

Same name and namespace in other branches
  1. 8.4 src/SmartlingTranslatorUi.php \Drupal\tmgmt_smartling\SmartlingTranslatorUi::checkoutSettingsForm()

Form callback for the checkout settings form.

Overrides TranslatorPluginUiBase::checkoutSettingsForm

File

src/SmartlingTranslatorUi.php, line 508
Contains \Drupal\tmgmt_smartling\SmartlingTranslatorUi.

Class

SmartlingTranslatorUi
Smartling translator UI.

Namespace

Drupal\tmgmt_smartling

Code

public function checkoutSettingsForm(array $form, FormStateInterface $form_state, JobInterface $job) {
  $plugin_id = $form_state
    ->getValue('translator');
  $translator = $form_state
    ->getFormObject()
    ->getEntity()
    ->getTranslator();
  $add_to_job_values = [];
  $user_input = $form_state
    ->getUserInput();

  // Pass needed values into "Add to job" form only on "Change job"
  // ajax event.
  if (!empty($user_input['_triggering_element_name']) && $user_input['_triggering_element_name'] == 'settings[add_to_job_tab][container][job_id]' && !empty($user_input['settings']['add_to_job_tab'])) {
    $add_to_job_values = $user_input['settings']['add_to_job_tab'];
  }
  if (!empty($plugin_id)) {
    $translator = Translator::load($plugin_id);
  }
  $form['smartling_users_time_zone'] = [
    '#type' => 'hidden',
  ];
  $form['switcher'] = [
    '#type' => 'radios',
    '#default_value' => 0,
    '#options' => [
      t('Create new job'),
      t('Add to job'),
    ],
  ];
  $form['create_new_job_tab'] = [
    '#type' => 'fieldset',
    '#title' => t('Create job'),
    '#states' => [
      'visible' => [
        ':input[name="settings[switcher]"]' => [
          'value' => 0,
        ],
      ],
    ],
  ] + $this
    ->checkoutSettingsCreateJobForm($translator);
  $form['add_to_job_tab'] = [
    '#type' => 'fieldset',
    '#title' => t('Add to job'),
    '#states' => [
      'visible' => [
        ':input[name="settings[switcher]"]' => [
          'value' => 1,
        ],
      ],
    ],
  ] + $this
    ->checkoutSettingsAddToJobForm($translator, [
    JobStatus::AWAITING_AUTHORIZATION,
    JobStatus::IN_PROGRESS,
    JobStatus::COMPLETED,
  ], $add_to_job_values);
  $form['#attached']['library'][] = 'tmgmt_smartling/checkout.settings';
  return parent::checkoutSettingsForm($form, $form_state, $job);
}