class LingotekSourceStatus in Lingotek Translation 3.4.x
Same name and namespace in other branches
- 8.2 src/Element/LingotekSourceStatus.php \Drupal\lingotek\Element\LingotekSourceStatus
- 4.0.x src/Element/LingotekSourceStatus.php \Drupal\lingotek\Element\LingotekSourceStatus
- 3.0.x src/Element/LingotekSourceStatus.php \Drupal\lingotek\Element\LingotekSourceStatus
- 3.1.x src/Element/LingotekSourceStatus.php \Drupal\lingotek\Element\LingotekSourceStatus
- 3.2.x src/Element/LingotekSourceStatus.php \Drupal\lingotek\Element\LingotekSourceStatus
- 3.3.x src/Element/LingotekSourceStatus.php \Drupal\lingotek\Element\LingotekSourceStatus
- 3.5.x src/Element/LingotekSourceStatus.php \Drupal\lingotek\Element\LingotekSourceStatus
- 3.6.x src/Element/LingotekSourceStatus.php \Drupal\lingotek\Element\LingotekSourceStatus
- 3.7.x src/Element/LingotekSourceStatus.php \Drupal\lingotek\Element\LingotekSourceStatus
- 3.8.x src/Element/LingotekSourceStatus.php \Drupal\lingotek\Element\LingotekSourceStatus
Provides a Lingotek source status element.
Plugin annotation
@RenderElement("lingotek_source_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\LingotekSourceStatus
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of LingotekSourceStatus
4 #type uses of LingotekSourceStatus
- LingotekInterfaceTranslationForm::buildForm in src/
Form/ LingotekInterfaceTranslationForm.php - Form constructor.
- LingotekManagementFormBase::getSourceStatus in src/
Form/ LingotekManagementFormBase.php - Gets the source status of an entity in a format ready to display.
- LingotekSourceStatusFormatter::viewValue in src/
Plugin/ Field/ FieldFormatter/ LingotekSourceStatusFormatter.php - Generate the output appropriate for one field item.
- LingotekTranslationStatusController::renderSource in tests/
modules/ lingotek_form_test/ src/ Controller/ LingotekTranslationStatusController.php - Renders the Lingotek source status of the given entity.
File
- src/
Element/ LingotekSourceStatus.php, line 15
Namespace
Drupal\lingotek\ElementView source
class LingotekSourceStatus extends RenderElement {
/**
* {@inheritdoc}
*/
public function getInfo() {
return [
'#pre_render' => [
[
$this,
'preRender',
],
],
'#theme' => 'lingotek_source_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) {
if (isset($element['#entity'])) {
$element['#url'] = $this
->getSourceActionUrl($element['#entity'], $element['#status']);
$element['#status_title'] = $this
->getSourceStatusText($element['#entity'], $element['#status']);
}
elseif (isset($element['#ui_component'])) {
$element['#url'] = $this
->getSourceActionUrlForUI($element['#ui_component'], $element['#status']);
$element['#status_title'] = $this
->getSourceStatusTextForUI($element['#ui_component'], $element['#status']);
}
return $element;
}
/**
* Get the source action url based on the source status.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity.
* @param string $source_status
* The source status.
*
* @return \Drupal\Core\Url
* An url object.
*/
protected function getSourceActionUrl(ContentEntityInterface &$entity, $source_status) {
$url = NULL;
if ($source_status == Lingotek::STATUS_IMPORTING) {
$url = Url::fromRoute('lingotek.entity.check_upload', [
'doc_id' => \Drupal::service('lingotek.content_translation')
->getDocumentId($entity),
], [
'query' => $this
->getDestinationWithQueryArray(),
]);
}
if ($source_status == Lingotek::STATUS_EDITED || $source_status == Lingotek::STATUS_UNTRACKED || $source_status == Lingotek::STATUS_ERROR || $source_status == Lingotek::STATUS_CANCELLED) {
if ($doc_id = \Drupal::service('lingotek.content_translation')
->getDocumentId($entity)) {
$url = Url::fromRoute('lingotek.entity.update', [
'doc_id' => $doc_id,
], [
'query' => $this
->getDestinationWithQueryArray(),
]);
}
else {
$url = Url::fromRoute('lingotek.entity.upload', [
'entity_type' => $entity
->getEntityTypeId(),
'entity_id' => $entity
->id(),
], [
'query' => $this
->getDestinationWithQueryArray(),
]);
}
}
return $url;
}
protected function getSourceActionUrlForUI($component, $source_status) {
$url = NULL;
if ($source_status == Lingotek::STATUS_IMPORTING) {
$url = Url::fromRoute('lingotek.interface_translation.check_upload', [], [
'query' => [
'component' => $component,
] + $this
->getDestinationWithQueryArray(),
]);
}
if ($source_status == Lingotek::STATUS_EDITED || $source_status == Lingotek::STATUS_UNTRACKED || $source_status == Lingotek::STATUS_ERROR || $source_status == Lingotek::STATUS_CANCELLED) {
if ($doc_id = \Drupal::service('lingotek.interface_translation')
->getDocumentId($component)) {
$url = Url::fromRoute('lingotek.interface_translation.update', [], [
'query' => [
'component' => $component,
] + $this
->getDestinationWithQueryArray(),
]);
}
else {
$url = Url::fromRoute('lingotek.interface_translation.upload', [], [
'query' => [
'component' => $component,
] + $this
->getDestinationWithQueryArray(),
]);
}
}
return $url;
}
/**
* Get the source status label.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity.
* @param string $source_status
* The source status
*
* @return string
* The source status human-friendly label.
*/
protected function getSourceStatusText(ContentEntityInterface $entity, $source_status) {
switch ($source_status) {
case Lingotek::STATUS_UNTRACKED:
case Lingotek::STATUS_REQUEST:
return t('Upload');
case Lingotek::STATUS_DISABLED:
return t('Disabled, cannot request translation');
case Lingotek::STATUS_EDITED:
return \Drupal::service('lingotek.content_translation')
->getDocumentId($entity) ? t('Re-upload (content has changed since last upload)') : t('Upload');
case Lingotek::STATUS_IMPORTING:
return t('Source importing');
case Lingotek::STATUS_CURRENT:
return t('Source uploaded');
case Lingotek::STATUS_ERROR:
return t('Error');
case Lingotek::STATUS_CANCELLED:
return $this
->t('Cancelled by user');
default:
return ucfirst(strtolower($source_status));
}
}
protected function getSourceStatusTextForUI($component, $source_status) {
switch ($source_status) {
case Lingotek::STATUS_UNTRACKED:
case Lingotek::STATUS_REQUEST:
return t('Upload');
case Lingotek::STATUS_DISABLED:
return t('Disabled, cannot request translation');
case Lingotek::STATUS_EDITED:
return \Drupal::service('lingotek.interface_translation')
->getDocumentId($component) ? t('Re-upload (content has changed since last upload)') : t('Upload');
case Lingotek::STATUS_IMPORTING:
return t('Source importing');
case Lingotek::STATUS_CURRENT:
return t('Source uploaded');
case Lingotek::STATUS_ERROR:
return t('Error');
case Lingotek::STATUS_CANCELLED:
return $this
->t('Cancelled by user');
default:
return ucfirst(strtolower($source_status));
}
}
/**
* 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 | |
LingotekSourceStatus:: |
protected | function | Get a destination query with the current uri. | |
LingotekSourceStatus:: |
public | function |
Returns the element properties for this element. Overrides ElementInterface:: |
|
LingotekSourceStatus:: |
protected | function | Get the source action url based on the source status. | |
LingotekSourceStatus:: |
protected | function | ||
LingotekSourceStatus:: |
protected | function | Get the source status label. | |
LingotekSourceStatus:: |
protected | function | ||
LingotekSourceStatus:: |
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. |