public function KickerFormatter::viewInstantArticle in Facebook Instant Articles 3.x
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/KickerFormatter.php \Drupal\fb_instant_articles\Plugin\Field\FieldFormatter\KickerFormatter::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/ KickerFormatter.php, line 27
Class
- KickerFormatter
- Plugin implementation of the 'fbia_kicker' formatter.
Namespace
Drupal\fb_instant_articles\Plugin\Field\FieldFormatterCode
public function viewInstantArticle(FieldItemListInterface $items, InstantArticle $article, $region, NormalizerInterface $normalizer, $langcode = NULL) {
// Kickers are only added to the header. Get the header, creating it if need
// be.
$header = $article
->getHeader();
if (!$header) {
$header = Header::create();
$article
->withHeader($header);
}
// Note that there can only be one kicker. We use the first value as the
// kicker.
if ($item = $items
->get(0)) {
$header
->withKicker($items
->get(0)->value);
}
}