class LingotekEntityController in Lingotek Translation 8
Same name and namespace in other branches
- 8.2 src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController
- 4.0.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController
- 3.0.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController
- 3.1.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController
- 3.2.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController
- 3.3.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController
- 3.4.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController
- 3.5.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController
- 3.6.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController
- 3.7.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController
- 3.8.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController
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\LingotekEntityController
- class \Drupal\lingotek\Controller\LingotekControllerBase uses LingotekSetupTrait
Expanded class hierarchy of LingotekEntityController
File
- src/
Controller/ LingotekEntityController.php, line 12
Namespace
Drupal\lingotek\ControllerView source
class LingotekEntityController extends LingotekControllerBase {
protected $translations_link;
public function checkUpload($doc_id) {
/** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
$translation_service = \Drupal::service('lingotek.content_translation');
$entity = $translation_service
->loadByDocumentId($doc_id);
if (!$entity) {
// TODO: log warning
return $this
->translationsPageRedirect($entity);
}
try {
if ($translation_service
->checkSourceStatus($entity)) {
drupal_set_message(t('The import for @entity_type %title is complete.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
)));
}
else {
drupal_set_message(t('The import for @entity_type %title is still pending.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
)));
}
} catch (LingotekApiException $exception) {
drupal_set_message(t('The check for @entity_type status failed. Please try again.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
)), 'error');
}
return $this
->translationsPageRedirect($entity);
}
public function checkTarget($doc_id, $locale) {
/** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
$translation_service = \Drupal::service('lingotek.content_translation');
$entity = $translation_service
->loadByDocumentId($doc_id);
if (!$entity) {
// TODO: log warning
return $this
->translationsPageRedirect($entity);
}
$drupal_language = $this->languageLocaleMapper
->getConfigurableLanguageForLocale($locale);
try {
if ($translation_service
->checkTargetStatus($entity, $drupal_language
->id()) === Lingotek::STATUS_READY) {
drupal_set_message(t('The @locale translation for @entity_type %title is ready for download.', array(
'@locale' => $locale,
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
)));
}
else {
drupal_set_message(t('The @locale translation for @entity_type %title is still in progress.', array(
'@locale' => $locale,
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
)));
}
} catch (LingotekApiException $exc) {
drupal_set_message(t('The request for @entity_type translation status failed. Please try again.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
)), 'error');
}
return $this
->translationsPageRedirect($entity);
}
public function addTarget($doc_id, $locale) {
/** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
$translation_service = \Drupal::service('lingotek.content_translation');
$entity = $translation_service
->loadByDocumentId($doc_id);
if (!$entity) {
// TODO: log warning
return $this
->translationsPageRedirect($entity);
}
try {
if ($translation_service
->addTarget($entity, $locale)) {
drupal_set_message(t("Locale '@locale' was added as a translation target for @entity_type %title.", array(
'@locale' => $locale,
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
)));
}
else {
drupal_set_message(t("There was a problem adding '@locale' as a translation target for @entity_type %title.", array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
'@locale' => $locale,
)), 'warning');
}
} catch (LingotekApiException $exception) {
drupal_set_message(t('The translation request for @entity_type failed. Please try again.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
)), 'error');
}
return $this
->translationsPageRedirect($entity);
}
public function upload($entity_type, $entity_id) {
/** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
$translation_service = \Drupal::service('lingotek.content_translation');
$entity = $this
->entityManager()
->getStorage($entity_type)
->load($entity_id);
try {
if ($translation_service
->uploadDocument($entity)) {
drupal_set_message(t('@entity_type %title has been uploaded.', [
'@entity_type' => ucfirst($entity
->getEntityTypeId()),
'%title' => $entity
->label(),
]));
}
} catch (LingotekApiException $exception) {
$translation_service
->setSourceStatus($entity, Lingotek::STATUS_ERROR);
drupal_set_message(t('The upload for @entity_type %title failed. Please try again.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
)), 'error');
}
return $this
->translationsPageRedirect($entity);
}
public function update($doc_id) {
/** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
$translation_service = \Drupal::service('lingotek.content_translation');
$entity = $translation_service
->loadByDocumentId($doc_id);
try {
if ($translation_service
->updateDocument($entity)) {
drupal_set_message(t('@entity_type %title has been updated.', [
'@entity_type' => ucfirst($entity
->getEntityTypeId()),
'%title' => $entity
->label(),
]));
}
} catch (LingotekApiException $exception) {
$translation_service
->setSourceStatus($entity, Lingotek::STATUS_ERROR);
drupal_set_message(t('The update for @entity_type %title failed. Please try again.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
)), 'error');
}
return $this
->translationsPageRedirect($entity);
}
public function download($doc_id, $locale) {
/** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
$translation_service = \Drupal::service('lingotek.content_translation');
$entity = $translation_service
->loadByDocumentId($doc_id);
if (!$entity) {
// TODO: log warning
return $this
->translationsPageRedirect($entity);
}
try {
if ($translation_service
->downloadDocument($entity, $locale)) {
drupal_set_message(t('The translation of @entity_type %title into @locale has been downloaded.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
'@locale' => $locale,
)));
}
else {
drupal_set_message(t('The translation of @entity_type %title into @locale failed to download.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
'@locale' => $locale,
)), 'error');
}
} catch (LingotekApiException $exception) {
drupal_set_message(t('The download for @entity_type failed. Please try again.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
)), 'error');
} catch (LingotekContentEntityStorageException $storage_exception) {
drupal_set_message(t('The download for @entity_type %title failed because of the length of one field translation value: %table.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
'%table' => $storage_exception
->getTable(),
)), 'error');
}
return $this
->translationsPageRedirect($entity);
}
protected function translationsPageRedirect(EntityInterface $entity) {
$entity_type_id = $entity
->getEntityTypeId();
$uri = Url::fromRoute("entity.{$entity_type_id}.content_translation_overview", [
$entity_type_id => $entity
->id(),
]);
$entity_type = $entity
->getEntityType();
if ($entity_type
->hasLinkTemplate('canonical')) {
return new RedirectResponse($uri
->setAbsolute(TRUE)
->toString());
}
else {
return new RedirectResponse($this->request
->getUri());
}
}
}
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. | |
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:: |
1 |
LingotekControllerBase:: |
protected | function | Return a Lingotek form (convenience function) | |
LingotekControllerBase:: |
public | function | Constructs a LingotekControllerBase object. | 1 |
LingotekEntityController:: |
protected | property | ||
LingotekEntityController:: |
public | function | ||
LingotekEntityController:: |
public | function | ||
LingotekEntityController:: |
public | function | ||
LingotekEntityController:: |
public | function | ||
LingotekEntityController:: |
protected | function | ||
LingotekEntityController:: |
public | function | ||
LingotekEntityController:: |
public | function | ||
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. |