LingotekSourceStatusFormatter.php in Lingotek Translation 4.0.x
Same filename and directory in other branches
- 8.2 src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php
- 3.0.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php
- 3.1.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php
- 3.2.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php
- 3.3.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php
- 3.4.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php
- 3.5.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php
- 3.6.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php
- 3.7.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php
- 3.8.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php
File
src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.phpView source
<?php
namespace Drupal\lingotek\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\LanguageFormatter;
use Drupal\Core\Form\FormStateInterface;
use Drupal\lingotek\Entity\LingotekContentMetadata;
use Drupal\lingotek\Lingotek;
/**
* Plugin implementation of the 'lingotek_translation_status' formatter.
*
* @FieldFormatter(
* id = "lingotek_source_status",
* label = @Translation("Lingotek source status"),
* field_types = {
* "language",
* }
* )
*/
class LingotekSourceStatusFormatter extends LanguageFormatter {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
$settings = [];
return $settings;
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = [];
return $form;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = [];
return $summary;
}
/**
* {@inheritdoc}
*/
protected function viewValue(FieldItemInterface $item) {
$entity = $item
->getEntity();
$source_status = Lingotek::STATUS_UNTRACKED;
if ($entity instanceof LingotekContentMetadata) {
// $entity is the metadata of another entity. Let's get the source.
// ToDo: Use injected service. See https://www.drupal.org/project/drupal/issues/2981025#comment-12707077.
$entity = \Drupal::entityTypeManager()
->getStorage($entity
->getContentEntityTypeId())
->load($entity
->getContentEntityId());
$source_status = \Drupal::service('lingotek.content_translation')
->getSourceStatus($entity);
}
$data = [
'data' => [
'#type' => 'lingotek_source_status',
'#entity' => $entity,
'#language' => $item->language,
'#status' => $source_status,
],
'#attached' => [
'library' => [
'lingotek/lingotek',
],
],
'#cache' => [
'max-age' => 0,
],
];
if ($source_status == Lingotek::STATUS_EDITED && !\Drupal::service('lingotek.content_translation')
->getDocumentId($entity)) {
$data['data']['#context']['status'] = strtolower(Lingotek::STATUS_REQUEST);
}
return $data;
}
protected function getDestinationWithQueryArray() {
return [
'destination' => \Drupal::request()
->getRequestUri(),
];
}
}
Classes
Name![]() |
Description |
---|---|
LingotekSourceStatusFormatter | Plugin implementation of the 'lingotek_translation_status' formatter. |