You are here

public function LingotekSetupController::defaultsPage in Lingotek Translation 3.5.x

Same name and namespace in other branches
  1. 8 src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::defaultsPage()
  2. 8.2 src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::defaultsPage()
  3. 4.0.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::defaultsPage()
  4. 3.0.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::defaultsPage()
  5. 3.1.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::defaultsPage()
  6. 3.2.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::defaultsPage()
  7. 3.3.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::defaultsPage()
  8. 3.4.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::defaultsPage()
  9. 3.6.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::defaultsPage()
  10. 3.7.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::defaultsPage()
  11. 3.8.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::defaultsPage()
1 string reference to 'LingotekSetupController::defaultsPage'
lingotek.routing.yml in ./lingotek.routing.yml
lingotek.routing.yml

File

src/Controller/LingotekSetupController.php, line 103

Class

LingotekSetupController
Returns responses for lingotek module setup routes.

Namespace

Drupal\lingotek\Controller

Code

public function defaultsPage() {
  if ($redirect = $this
    ->checkSetup()) {
    return $redirect;
  }
  $resources = $this->lingotek
    ->getResources();

  // No choice necessary. Save and advance to the next page.
  if (count($resources['project']) == 1 && count($resources['vault']) == 1) {
    $config = \Drupal::configFactory()
      ->getEditable('lingotek.settings');
    $config
      ->set('default.project', current(array_keys($resources['project'])));
    $config
      ->set('default.vault', current(array_keys($resources['vault'])));
    $default_workflow = array_search('Machine Translation', $resources['workflow']);
    if ($default_workflow === FALSE) {
      $default_workflow = current(array_keys($resources['workflow']));
    }
    $config
      ->set('default.workflow', $default_workflow);

    // Assign the project callback
    $new_callback_url = \Drupal::urlGenerator()
      ->generateFromRoute('lingotek.notify', [], [
      'absolute' => TRUE,
    ]);
    $config
      ->set('account.callback_url', $new_callback_url);
    $config
      ->save();
    $new_response = $this->lingotek
      ->setProjectCallBackUrl($config
      ->get('default.project'), $new_callback_url);
    return $this
      ->redirect('lingotek.dashboard');
  }
  return [
    '#type' => 'markup',
    'markup' => $this->formBuilder
      ->getForm(LingotekSettingsDefaultsForm::class),
  ];
}