You are here

public function LingotekSetupController::communityPage in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::communityPage()
  2. 4.0.x 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 61

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');
  }
  $config = \Drupal::configFactory()
    ->getEditable('lingotek.settings');
  $config
    ->set('account.resources.community', $communities);
  $config
    ->save();
  if (count($communities) == 1) {

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

    // update resources based on newly selected community
    return $this
      ->redirect('lingotek.setup_defaults');
  }
  return array(
    '#type' => 'markup',
    'markup' => $this
      ->getLingotekForm('LingotekSettingsCommunityForm'),
  );
}