class LingotekTargetStatus in Lingotek Translation 3.4.x
Same name and namespace in other branches
- 8.2 src/Element/LingotekTargetStatus.php \Drupal\lingotek\Element\LingotekTargetStatus
- 4.0.x src/Element/LingotekTargetStatus.php \Drupal\lingotek\Element\LingotekTargetStatus
- 3.0.x src/Element/LingotekTargetStatus.php \Drupal\lingotek\Element\LingotekTargetStatus
- 3.1.x src/Element/LingotekTargetStatus.php \Drupal\lingotek\Element\LingotekTargetStatus
- 3.2.x src/Element/LingotekTargetStatus.php \Drupal\lingotek\Element\LingotekTargetStatus
- 3.3.x src/Element/LingotekTargetStatus.php \Drupal\lingotek\Element\LingotekTargetStatus
- 3.5.x src/Element/LingotekTargetStatus.php \Drupal\lingotek\Element\LingotekTargetStatus
- 3.6.x src/Element/LingotekTargetStatus.php \Drupal\lingotek\Element\LingotekTargetStatus
- 3.7.x src/Element/LingotekTargetStatus.php \Drupal\lingotek\Element\LingotekTargetStatus
- 3.8.x src/Element/LingotekTargetStatus.php \Drupal\lingotek\Element\LingotekTargetStatus
Provides a Lingotek target status element.
Plugin annotation
@RenderElement("lingotek_target_status");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\lingotek\Element\LingotekTargetStatus
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of LingotekTargetStatus
2 #type uses of LingotekTargetStatus
- LingotekTranslationStatusController::renderTargetStatus in tests/
modules/ lingotek_form_test/ src/ Controller/ LingotekTranslationStatusController.php - Renders the Lingotek target status of the given entity.
- LingotekTranslationStatusFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ LingotekTranslationStatusFormatter.php - Builds a renderable array for a field value.
File
- src/
Element/ LingotekTargetStatus.php, line 16
Namespace
Drupal\lingotek\ElementView source
class LingotekTargetStatus extends RenderElement {
/**
* {@inheritdoc}
*/
public function getInfo() {
return [
'#pre_render' => [
[
$this,
'preRender',
],
],
'#theme' => 'lingotek_target_status',
'#attached' => [
'library' => [
'lingotek/lingotek',
],
],
'#cache' => [
'max-age' => 0,
],
];
}
/**
* Calculates the url and status title and adds them to the render array.
*
* @param array $element
* The element as a render array.
*
* @return array
* The element as a render array.
*/
public function preRender(array $element) {
$isSourceLanguage = $element['#entity']
->language()
->getId() === $element['#language'];
if ($isSourceLanguage) {
return [];
}
if (NULL === ConfigurableLanguage::load($element['#language'])) {
return [];
}
$element['#url'] = $this
->getTargetActionUrl($element['#entity'], $element['#status'], $element['#language']);
$element['#new_window'] = !($element['#entity']
->hasTranslation($element['#language']) && $element['#status'] == Lingotek::STATUS_REQUEST) && in_array($element['#status'], [
Lingotek::STATUS_CURRENT,
Lingotek::STATUS_INTERMEDIATE,
Lingotek::STATUS_EDITED,
]);
$element['#status_text'] = $this
->getTargetStatusText($element['#entity'], $element['#status'], $element['#language']);
return $element;
}
/**
* Get the source status label.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity.
* @param string $status
* The target status.
* @param string $langcode
* The language code.
*
* @return string
* The source status human-friendly label.
*/
protected function getTargetStatusText(ContentEntityInterface $entity, $status, $langcode) {
$language = ConfigurableLanguage::load($langcode);
switch ($status) {
case Lingotek::STATUS_UNTRACKED:
return $language
->label() . ' - ' . $this
->t('Translation exists, but it is not being tracked by Lingotek');
case Lingotek::STATUS_REQUEST:
return $language
->label() . ' - ' . $this
->t('Request translation');
case Lingotek::STATUS_PENDING:
return $language
->label() . ' - ' . $this
->t('In-progress');
case Lingotek::STATUS_READY:
return $language
->label() . ' - ' . $this
->t('Ready for Download');
case Lingotek::STATUS_INTERMEDIATE:
return $language
->label() . ' - ' . $this
->t('In-progress (interim translation downloaded)');
case Lingotek::STATUS_CURRENT:
return $language
->label() . ' - ' . $this
->t('Current');
case Lingotek::STATUS_EDITED:
return $language
->label() . ' - ' . $this
->t('Not current');
case Lingotek::STATUS_ERROR:
return $language
->label() . ' - ' . $this
->t('Error');
case Lingotek::STATUS_CANCELLED:
return $language
->label() . ' - ' . $this
->t('Cancelled by user');
default:
return $language
->label() . ' - ' . ucfirst(strtolower($status));
}
}
/**
* Get the target action url based on the source status.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity.
* @param string $target_status
* The target status.
* @param string $langcode
* The language code.
*
* @return \Drupal\Core\Url
* An url object.
*/
protected function getTargetActionUrl(ContentEntityInterface &$entity, $target_status, $langcode) {
$url = NULL;
$document_id = \Drupal::service('lingotek.content_translation')
->getDocumentId($entity);
$locale = \Drupal::service('lingotek.language_locale_mapper')
->getLocaleForLangcode($langcode);
if ($document_id) {
if ($target_status == Lingotek::STATUS_REQUEST) {
$url = Url::fromRoute('lingotek.entity.request_translation', [
'doc_id' => $document_id,
'locale' => $locale,
], [
'query' => $this
->getDestinationWithQueryArray(),
]);
}
if ($target_status == Lingotek::STATUS_PENDING) {
$url = Url::fromRoute('lingotek.entity.check_target', [
'doc_id' => $document_id,
'locale' => $locale,
], [
'query' => $this
->getDestinationWithQueryArray(),
]);
}
if ($target_status == Lingotek::STATUS_READY || $target_status == Lingotek::STATUS_ERROR) {
$url = Url::fromRoute('lingotek.entity.download', [
'doc_id' => $document_id,
'locale' => $locale,
], [
'query' => $this
->getDestinationWithQueryArray(),
]);
}
if ($target_status == Lingotek::STATUS_CURRENT || $target_status == Lingotek::STATUS_INTERMEDIATE || $target_status == Lingotek::STATUS_EDITED) {
$url = Url::fromRoute('lingotek.workbench', [
'doc_id' => $document_id,
'locale' => $locale,
]);
}
if ($target_status == Lingotek::STATUS_UNTRACKED) {
$url = Url::fromRoute('lingotek.entity.request_translation', [
'doc_id' => $document_id,
'locale' => $locale,
], [
'query' => $this
->getDestinationWithQueryArray(),
]);
}
}
return $url;
}
/**
* Get a destination query with the current uri.
*
* @return array
* A valid query array for the Url construction.
*/
protected function getDestinationWithQueryArray() {
return [
'destination' => \Drupal::request()
->getRequestUri(),
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
LingotekTargetStatus:: |
protected | function | Get a destination query with the current uri. | |
LingotekTargetStatus:: |
public | function |
Returns the element properties for this element. Overrides ElementInterface:: |
|
LingotekTargetStatus:: |
protected | function | Get the target action url based on the source status. | |
LingotekTargetStatus:: |
protected | function | Get the source status label. | |
LingotekTargetStatus:: |
public | function | Calculates the url and status title and adds them to the render array. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 98 |
RenderElement:: |
public static | function | Adds Ajax information about an element to communicate with JavaScript. | |
RenderElement:: |
public static | function | Adds members of this group as actual elements for rendering. | |
RenderElement:: |
public static | function | Form element processing handler for the #ajax form property. | 1 |
RenderElement:: |
public static | function | Arranges elements into groups. | |
RenderElement:: |
public static | function |
Sets a form element's class attribute. Overrides ElementInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
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. |