You are here

public function LingotekTranslationStatusesFormatter::view in Lingotek Translation 3.4.x

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

Builds a renderable array for a fully themed field.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.

string $langcode: (optional) The language that should be used to render the field. Defaults to the current content language.

Return value

array A renderable array for a themed field with its label and all its values.

Overrides FormatterBase::view

File

src/Plugin/Field/FieldFormatter/LingotekTranslationStatusesFormatter.php, line 43

Class

LingotekTranslationStatusesFormatter
Plugin implementation of the 'lingotek_translation_statuses' formatter.

Namespace

Drupal\lingotek\Plugin\Field\FieldFormatter

Code

public function view(FieldItemListInterface $items, $langcode = NULL) {
  $entity = $items
    ->getEntity();
  if ($entity instanceof LingotekContentMetadata) {

    // $entity is the metadata of another entity. Let's get the source.
    $entity = \Drupal::entityTypeManager()
      ->getStorage($entity
      ->getContentEntityTypeId())
      ->load($entity
      ->getContentEntityId());
  }
  $statuses = [];
  foreach ($items as $delta => $item) {
    $value = $item
      ->getValue();
    $langcode = $value['language'];
    $status = $value['value'];
    $statuses[$langcode] = $status;
  }
  return [
    '0' => [
      '#type' => 'lingotek_target_statuses',
      '#entity' => $entity,
      '#source_langcode' => $entity
        ->language()
        ->getId(),
      '#statuses' => $statuses,
    ],
    '#items' => [
      '0' => [
        '#type' => 'lingotek_target_statuses',
        '#entity' => $entity,
        '#source_langcode' => $entity
          ->language()
          ->getId(),
        '#statuses' => $statuses,
      ],
    ],
    '#attached' => [
      'library' => [
        'lingotek/lingotek',
      ],
    ],
    '#cache' => [
      'max-age' => 0,
    ],
  ];
}