public function SocialAlbumEntityReferenceLabelFormatter::viewElements in Open Social 10.1.x
Same name and namespace in other branches
- 10.3.x modules/social_features/social_album/src/Plugin/Field/FieldFormatter/SocialAlbumEntityReferenceLabelFormatter.php \Drupal\social_album\Plugin\Field\FieldFormatter\SocialAlbumEntityReferenceLabelFormatter::viewElements()
- 10.0.x modules/social_features/social_album/src/Plugin/Field/FieldFormatter/SocialAlbumEntityReferenceLabelFormatter.php \Drupal\social_album\Plugin\Field\FieldFormatter\SocialAlbumEntityReferenceLabelFormatter::viewElements()
- 10.2.x modules/social_features/social_album/src/Plugin/Field/FieldFormatter/SocialAlbumEntityReferenceLabelFormatter.php \Drupal\social_album\Plugin\Field\FieldFormatter\SocialAlbumEntityReferenceLabelFormatter::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 EntityReferenceLabelFormatter::viewElements
File
- modules/
social_features/ social_album/ src/ Plugin/ Field/ FieldFormatter/ SocialAlbumEntityReferenceLabelFormatter.php, line 27
Class
- SocialAlbumEntityReferenceLabelFormatter
- Plugin implementation of the 'social album entity reference label' formatter.
Namespace
Drupal\social_album\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = parent::viewElements($items, $langcode);
foreach ($items as $delta => $item) {
if (!isset($elements[$delta])) {
continue;
}
$cache = $elements[$delta]['#cache'];
if (isset($elements[$delta]['#title'])) {
$elements[$delta] = [
'#markup' => $this
->t('Images posted in album %album', [
'%album' => Link::fromTextAndUrl($elements[$delta]['#title'], $elements[$delta]['#url'])
->toString(),
]),
];
}
else {
$elements[$delta] = [
'#plain_text' => $this
->t('Images posted in album %album', [
'%album' => $elements[$delta]['#plain_text'],
]),
];
}
$elements[$delta]['#cache'] = $cache;
}
return $elements;
}