You are here

public function LingotekBatchController::dispatch in Lingotek Translation 3.5.x

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

File

src/Controller/LingotekBatchController.php, line 10

Class

LingotekBatchController

Namespace

Drupal\lingotek\Controller

Code

public function dispatch($action, $entity_type, $entity_id) {

  /** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
  $translation_service = \Drupal::service('lingotek.content_translation');

  /** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $configuration_service */
  $configuration_service = \Drupal::service('lingotek.configuration');

  /** @var \Drupal\lingotek\Lingotek $lingotek */
  $lingotek = \Drupal::service('lingotek');
  $entity = \Drupal::entityTypeManager()
    ->getStorage($entity_type)
    ->load($entity_id);

  // This forces the hash to be set.
  if ($translation_service
    ->hasEntityChanged($entity)) {
    $entity
      ->save();
  }
  $profile = $configuration_service
    ->getEntityProfile($entity, TRUE);
  switch ($action) {
    case 'uploadSingle':
      return $this
        ->uploadSingle($entity_type, $entity_id, $profile);
    case 'downloadSingle':
      return $this
        ->downloadSingle($entity_type, $entity_id, $profile);
    default:
      return $this
        ->noAction();
  }
}