fb_instant_articles-8.x-2.2/src/Plugin/Field/FieldFormatter/PullquoteFormatter.php

src/Plugin/Field/FieldFormatter/PullquoteFormatter.php
<?php

namespace Drupal\fb_instant_articles\Plugin\Field\FieldFormatter;

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

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

  /**
   * {@inheritdoc}
   */
  public function viewInstantArticle(FieldItemListInterface $items, InstantArticle $article, $region, NormalizerInterface $normalizer, $langcode = NULL) {
    foreach ($items as $delta => $item) {
      // Blockquotes 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(
        Pullquote::create()
          ->appendText($item->value)
      );
    }
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc