You are here

public function LingotekSetupController::communityPage in Lingotek Translation 4.0.x

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

File

src/Controller/LingotekSetupController.php, line 76

Class

LingotekSetupController
Returns responses for lingotek module setup routes.

Namespace

Drupal\lingotek\Controller

Code

public function communityPage() {
  if ($redirect = $this
    ->checkSetup()) {
    return $redirect;
  }
  $communities = $this->lingotek
    ->getCommunities(TRUE);
  if (empty($communities)) {

    // TODO: Log an error that no communities exist.
    return $this
      ->redirect('lingotek.setup_account');
  }
  $accountConfig = \Drupal::configFactory()
    ->getEditable('lingotek.account');
  $accountConfig
    ->set('resources.community', $communities);
  $accountConfig
    ->save();
  if (count($communities) == 1) {

    // No choice necessary. Save and advance to next page.
    $accountConfig
      ->set('default.community', current(array_keys($communities)));
    $accountConfig
      ->save();

    // update resources based on newly selected community
    $this->lingotek
      ->getResources(TRUE);
    return $this
      ->redirect('lingotek.setup_defaults');
  }
  return [
    '#type' => 'markup',
    'markup' => $this->formBuilder
      ->getForm(LingotekSettingsCommunityForm::class),
  ];
}