LingotekSourceStatusFormatter.php in Lingotek Translation 8.2
File
src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php
View 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;
class LingotekSourceStatusFormatter extends LanguageFormatter {
public static function defaultSettings() {
$settings = [];
return $settings;
}
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = [];
return $form;
}
public function settingsSummary() {
$summary = [];
return $summary;
}
protected function viewValue(FieldItemInterface $item) {
$entity = $item
->getEntity();
$source_status = Lingotek::STATUS_UNTRACKED;
if ($entity instanceof LingotekContentMetadata) {
$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(),
];
}
}