class LingotekBatchController in Lingotek Translation 8.2
Same name and namespace in other branches
- 8 src/Controller/LingotekBatchController.php \Drupal\lingotek\Controller\LingotekBatchController
- 4.0.x src/Controller/LingotekBatchController.php \Drupal\lingotek\Controller\LingotekBatchController
- 3.0.x src/Controller/LingotekBatchController.php \Drupal\lingotek\Controller\LingotekBatchController
- 3.1.x src/Controller/LingotekBatchController.php \Drupal\lingotek\Controller\LingotekBatchController
- 3.2.x src/Controller/LingotekBatchController.php \Drupal\lingotek\Controller\LingotekBatchController
- 3.3.x src/Controller/LingotekBatchController.php \Drupal\lingotek\Controller\LingotekBatchController
- 3.4.x src/Controller/LingotekBatchController.php \Drupal\lingotek\Controller\LingotekBatchController
- 3.5.x src/Controller/LingotekBatchController.php \Drupal\lingotek\Controller\LingotekBatchController
- 3.6.x src/Controller/LingotekBatchController.php \Drupal\lingotek\Controller\LingotekBatchController
- 3.7.x src/Controller/LingotekBatchController.php \Drupal\lingotek\Controller\LingotekBatchController
- 3.8.x src/Controller/LingotekBatchController.php \Drupal\lingotek\Controller\LingotekBatchController
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\lingotek\Controller\LingotekControllerBase uses LingotekSetupTrait
- class \Drupal\lingotek\Controller\LingotekBatchController
- class \Drupal\lingotek\Controller\LingotekControllerBase uses LingotekSetupTrait
Expanded class hierarchy of LingotekBatchController
File
- src/
Controller/ LingotekBatchController.php, line 8
Namespace
Drupal\lingotek\ControllerView source
class LingotekBatchController extends LingotekControllerBase {
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();
}
}
public function uploadSingle($entity_type, $entity_id, LingotekProfile $profile = NULL) {
$batch = [
'title' => $this
->t('Uploading content to Lingotek'),
'operations' => $this
->getUploadOperations($entity_type, [
$entity_id,
]),
'error_message' => t('An error happened.'),
'finished' => 'lingotek_operation_content_upload_finished',
'file' => drupal_get_path('module', 'lingotek') . '/lingotek.batch.inc',
];
$redirect_url = \Drupal::urlGenerator()
->generate("entity.{$entity_type}.content_translation_overview", [
$entity_type => $entity_id,
], UrlGeneratorInterface::ABSOLUTE_URL);
batch_set($batch);
return batch_process($redirect_url);
}
public function downloadSingle($entity_type, $entity_id, $locales) {
$batch = [
'title' => $this
->t('Downloading translations from Lingotek'),
'operations' => $this
->getDownloadOperations($entity_type, [
$entity_id,
], $locales),
'finished' => 'lingotek_operation_content_download_finished',
'file' => drupal_get_path('module', 'lingotek') . '/lingotek.batch.inc',
];
$entity = \Drupal::entityTypeManager()
->getStorage($entity_type)
->load($entity_id);
$redirect_url = \Drupal::urlGenerator()
->generate("entity.{$entity_type}.content_translation_overview", [
$entity_type => $entity_id,
], UrlGeneratorInterface::ABSOLUTE_URL);
batch_set($batch);
return batch_process($redirect_url);
}
public function checkUploadStatus($entity_type, $entity_id) {
// TODO
}
public function checkTargetStatus($entity_type, $entity_id) {
// TODO
}
public function addLanguageSingle($entity_type, $entity_id) {
// TODO
}
protected function getUploadOperations($entity_type, $entity_ids) {
$operations = [];
if (is_array($entity_ids)) {
foreach ($entity_ids as $id) {
$operations[] = [
'lingotek_operation_content_upload',
[
$entity_type,
$id,
],
];
}
}
return $operations;
}
protected function getDownloadOperations($entity_type, $entity_ids, $locales) {
$operations = [];
if (is_array($entity_ids)) {
foreach ($entity_ids as $id) {
foreach ($locales as $locale) {
$operations[] = [
'lingotek_operation_translation_download',
[
$entity_type,
$id,
$locale,
],
];
}
}
}
return $operations;
}
public function noAction() {
$markup = $this
->t('Lingotek batch operation error: You must supply a valid action.');
return [
'#type' => 'markup',
'#markup' => $markup,
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
LingotekBatchController:: |
public | function | ||
LingotekBatchController:: |
public | function | ||
LingotekBatchController:: |
public | function | ||
LingotekBatchController:: |
public | function | ||
LingotekBatchController:: |
public | function | ||
LingotekBatchController:: |
protected | function | ||
LingotekBatchController:: |
protected | function | ||
LingotekBatchController:: |
public | function | ||
LingotekBatchController:: |
public | function | ||
LingotekControllerBase:: |
protected | property |
The config factory. Overrides ControllerBase:: |
|
LingotekControllerBase:: |
protected | property |
The form builder. Overrides ControllerBase:: |
|
LingotekControllerBase:: |
protected | property | The language-locale mapper. | |
LingotekControllerBase:: |
protected | property | A logger instance. | |
LingotekControllerBase:: |
protected | property | A Symfony request instance | |
LingotekControllerBase:: |
public | function | Checks if site is connected to Lingotek. | |
LingotekControllerBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
4 |
LingotekControllerBase:: |
protected | function | Return a Lingotek form (convenience function) | |
LingotekControllerBase:: |
public | function | Constructs a LingotekControllerBase object. | 4 |
LingotekSetupTrait:: |
protected | property | A lingotek connector object | |
LingotekSetupTrait:: |
protected | function | Verify the Lingotek Translation module has been properly initialized. | |
LingotekSetupTrait:: |
public | function | Checks if Lingotek module is completely set up. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |