You are here

BlockquoteFormatter.php in Facebook Instant Articles 8.2

Same filename and directory in other branches
  1. 3.x src/Plugin/Field/FieldFormatter/BlockquoteFormatter.php

File

src/Plugin/Field/FieldFormatter/BlockquoteFormatter.php
View source
<?php

namespace Drupal\fb_instant_articles\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FieldItemListInterface;
use Facebook\InstantArticles\Elements\Blockquote;
use Facebook\InstantArticles\Elements\InstantArticle;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
 * Plugin implementation of the 'fbia_blockquote' formatter.
 *
 * @FieldFormatter(
 *   id = "fbia_blockquote",
 *   label = @Translation("FBIA Blockquote"),
 *   field_types = {
 *     "string",
 *     "string_long"
 *   }
 * )
 */
class BlockquoteFormatter extends FormatterBase {

  /**
   * {@inheritdoc}
   */
  public function viewInstantArticle(FieldItemListInterface $items, InstantArticle $article, $region, NormalizerInterface $normalizer, $langcode = NULL) {
    foreach ($items as $delta => $item) {

      // Blockquote's are only allowed in the content region, add it there
      // regardless of the given $region. Note that the FBIA SDK will sanitize
      // the value.
      $article
        ->addChild(Blockquote::create()
        ->appendText($item->value));
    }
  }

}

Classes

Namesort descending Description
BlockquoteFormatter Plugin implementation of the 'fbia_blockquote' formatter.