You are here

public function TmgmtSmartlingContextDebugForm::submitForm in TMGMT Translator Smartling 8.2

Same name and namespace in other branches
  1. 8.4 modules/tmgmt_smartling_context_debug/src/Form/TmgmtSmartlingContextDebugForm.php \Drupal\tmgmt_smartling_context_debug\Form\TmgmtSmartlingContextDebugForm::submitForm()
  2. 8 modules/tmgmt_smartling_context_debug/src/Form/TmgmtSmartlingContextDebugForm.php \Drupal\tmgmt_smartling_context_debug\Form\TmgmtSmartlingContextDebugForm::submitForm()
  3. 8.3 modules/tmgmt_smartling_context_debug/src/Form/TmgmtSmartlingContextDebugForm.php \Drupal\tmgmt_smartling_context_debug\Form\TmgmtSmartlingContextDebugForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

modules/tmgmt_smartling_context_debug/src/Form/TmgmtSmartlingContextDebugForm.php, line 68

Class

TmgmtSmartlingContextDebugForm
Form that helps to debug Smartling Context.

Namespace

Drupal\tmgmt_smartling_context_debug\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $settings = \Drupal::config('tmgmt.translator.smartling')
    ->get('settings');
  $filename = $form_state
    ->getValue('filename');
  $url = $form_state
    ->getValue('url');
  $current_user_name = \Drupal::currentUser()
    ->getAccountName();

  /** @var \Drupal\tmgmt_smartling\Context\ContextUploader $context_uploader */
  $context_uploader = \Drupal::getContainer()
    ->get('tmgmt_smartling.utils.context.uploader');
  if ($form_state
    ->getValue('do_direct_output')) {
    $html = $context_uploader
      ->getContextualizedPage($url, $settings, TRUE);
    \Drupal::getContainer()
      ->get('tmgmt_smartling.utils.context.user_auth')
      ->switchUser($current_user_name, TRUE);
    die($html);
  }
  elseif ($context_uploader
    ->isReadyAcceptContext($filename, $settings)) {
    $response = $context_uploader
      ->upload($url, $filename, $settings);
    \Drupal::getContainer()
      ->get('tmgmt_smartling.utils.context.user_auth')
      ->switchUser($current_user_name, TRUE);
    $message = print_r($response, TRUE);
    \Drupal::logger('tmgmt_smartling_context_debug')
      ->info($message);
    drupal_set_message('Smartling response: ' . $message);
  }
}