public function LingotekTranslationStatusFormatter::viewElements in Lingotek Translation 3.7.x
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/LingotekTranslationStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekTranslationStatusFormatter::viewElements()
- 4.0.x src/Plugin/Field/FieldFormatter/LingotekTranslationStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekTranslationStatusFormatter::viewElements()
- 3.0.x src/Plugin/Field/FieldFormatter/LingotekTranslationStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekTranslationStatusFormatter::viewElements()
- 3.1.x src/Plugin/Field/FieldFormatter/LingotekTranslationStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekTranslationStatusFormatter::viewElements()
- 3.2.x src/Plugin/Field/FieldFormatter/LingotekTranslationStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekTranslationStatusFormatter::viewElements()
- 3.3.x src/Plugin/Field/FieldFormatter/LingotekTranslationStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekTranslationStatusFormatter::viewElements()
- 3.4.x src/Plugin/Field/FieldFormatter/LingotekTranslationStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekTranslationStatusFormatter::viewElements()
- 3.5.x src/Plugin/Field/FieldFormatter/LingotekTranslationStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekTranslationStatusFormatter::viewElements()
- 3.6.x src/Plugin/Field/FieldFormatter/LingotekTranslationStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekTranslationStatusFormatter::viewElements()
- 3.8.x src/Plugin/Field/FieldFormatter/LingotekTranslationStatusFormatter.php \Drupal\lingotek\Plugin\Field\FieldFormatter\LingotekTranslationStatusFormatter::viewElements()
Builds a renderable array for a field value.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.
string $langcode: The language that should be used to render the field.
Return value
array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.
Overrides FormatterInterface::viewElements
File
- src/
Plugin/ Field/ FieldFormatter/ LingotekTranslationStatusFormatter.php, line 43
Class
- LingotekTranslationStatusFormatter
- Plugin implementation of the 'lingotek_translation_status' formatter.
Namespace
Drupal\lingotek\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$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());
}
$sourceLanguage = $entity
->language()
->getId();
foreach ($items as $delta => $item) {
$value = $item
->getValue();
$langcode = $value['language'];
$status = $value['value'];
if ($langcode !== $sourceLanguage) {
$elements[$delta] = [
'#type' => 'lingotek_target_status',
'#entity' => $entity,
'#language' => $langcode,
'#status' => $status,
];
}
}
$elements['#attached'] = [
'library' => [
'lingotek/lingotek',
'lingotek/lingotek.target_actions',
],
];
$elements['#cache'] = [
'max-age' => 0,
];
return $elements;
}