You are here

public function TmgmtSmartlingContextDebugForm::submitForm in TMGMT Translator Smartling 8

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.2 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) {

  // \Drupal::config('tmgmt.translator.smartling')->get('settings.orgID');
  $settings = \Drupal::config('tmgmt.translator.smartling')
    ->get('settings');
  $filename = $form_state
    ->getValue('filename');
  $url = $form_state
    ->getValue('url');

  /** @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);
    die($html);
  }
  elseif ($context_uploader
    ->isReadyAcceptContext($filename, $settings)) {
    $response = $context_uploader
      ->upload($url, $filename, $settings);
    $message = print_r($response, TRUE);
    \Drupal::logger('smartling_context')
      ->info($message);
    drupal_set_message('Smartling response: ' . $message);
  }
}