public function ListFormatter::viewInstantArticle in Facebook Instant Articles 8.2
Same name and namespace in other branches
- 3.x src/Plugin/Field/FieldFormatter/ListFormatter.php \Drupal\fb_instant_articles\Plugin\Field\FieldFormatter\ListFormatter::viewInstantArticle()
Modifies the given instant article with the contents of this field.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.
\Facebook\InstantArticles\Elements\InstantArticle $article: Instant article object to modify, rendering the contents of this field into it.
string $region: The Instant Article region name that the contents of this field should be rendered into.
\Symfony\Component\Serializer\Normalizer\NormalizerInterface $normalizer: Normalizer in case the formatter needs to recursively normalize, eg. in the case of a entity reference field.
string $langcode: (optional) The language that should be used to render the field. Defaults to the current content language.
Overrides InstantArticleFormatterInterface::viewInstantArticle
File
- src/
Plugin/ Field/ FieldFormatter/ ListFormatter.php, line 61
Class
- ListFormatter
- Plugin implementation of the 'fbia_list' formatter.
Namespace
Drupal\fb_instant_articles\Plugin\Field\FieldFormatterCode
public function viewInstantArticle(FieldItemListInterface $items, InstantArticle $article, $region, NormalizerInterface $normalizer, $langcode = NULL) {
if (!$items
->isEmpty()) {
if ($this
->getSetting('is_ordered')) {
$list = ListElement::createOrdered();
}
else {
$list = ListElement::createUnordered();
}
foreach ($items as $delta => $item) {
$list
->addItem(ListItem::create()
->appendText($item->value));
}
// Lists can only be added to the content part of an instant article, so
// we ignore $region.
$article
->addChild($list);
}
}