You are here

protected function LingotekSourceStatusFormatter::viewValue in Lingotek Translation 3.2.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekSourceStatusFormatter::viewValue()
  2. 4.0.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekSourceStatusFormatter::viewValue()
  3. 3.0.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekSourceStatusFormatter::viewValue()
  4. 3.1.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekSourceStatusFormatter::viewValue()
  5. 3.3.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekSourceStatusFormatter::viewValue()
  6. 3.4.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekSourceStatusFormatter::viewValue()
  7. 3.5.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekSourceStatusFormatter::viewValue()
  8. 3.6.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekSourceStatusFormatter::viewValue()
  9. 3.7.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekSourceStatusFormatter::viewValue()
  10. 3.8.x src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekSourceStatusFormatter::viewValue()

Generate the output appropriate for one field item.

Parameters

\Drupal\Core\Field\FieldItemInterface $item: One field item.

Return value

array The textual output generated as a render array.

Overrides LanguageFormatter::viewValue

File

src/Plugin/Field/FieldFormatter/LingotekSourceStatusFormatter.php, line 51

Class

LingotekSourceStatusFormatter
Plugin implementation of the 'lingotek_translation_status' formatter.

Namespace

Drupal\lingotek\Plugin\Field\FieldFormatter

Code

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;
}