public function TwitterWidgetFormatter::viewElements in Twitter Profile Widget 3.x
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/TwitterWidgetFormatter.php \Drupal\twitter_profile_widget\Plugin\Field\FieldFormatter\TwitterWidgetFormatter::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/ TwitterWidgetFormatter.php, line 27
Class
- TwitterWidgetFormatter
- Plugin implementation of the 'twitter_widget' formatter.
Namespace
Drupal\twitter_profile_widget\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode = NULL) {
$instances = $items
->getValue();
$elements = [];
foreach ($instances as $instance) {
$elements[] = [
'#theme' => 'twitter_profile_widget',
'#headline' => (string) $instance['headline'],
'#tweets' => $this
->getTweets($instance),
'#view_all' => $this
->getViewAll($instance),
];
}
return $elements;
}