ParagraphFormatter.php in Facebook Instant Articles 3.x
File
src/Plugin/Field/FieldFormatter/ParagraphFormatter.php
View source
<?php
namespace Drupal\fb_instant_articles\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Facebook\InstantArticles\Elements\InstantArticle;
use Facebook\InstantArticles\Elements\Paragraph;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class ParagraphFormatter extends FormatterBase {
public function viewInstantArticle(FieldItemListInterface $items, InstantArticle $article, $region, NormalizerInterface $normalizer, $langcode = NULL) {
foreach ($items as $delta => $item) {
$article
->addChild(Paragraph::create()
->appendText($item->value));
}
}
}