You are here

public function InstantArticleRssContentEntityNormalizer::normalize in Facebook Instant Articles 3.x

Same name and namespace in other branches
  1. 8.2 src/Normalizer/InstantArticleRssContentEntityNormalizer.php \Drupal\fb_instant_articles\Normalizer\InstantArticleRssContentEntityNormalizer::normalize()

File

src/Normalizer/InstantArticleRssContentEntityNormalizer.php, line 39

Class

InstantArticleRssContentEntityNormalizer
Extends the content entity normalizer that ships with the base module.

Namespace

Drupal\fb_instant_articles\Normalizer

Code

public function normalize($data, $format = NULL, array $context = []) {

  /** @var \Drupal\Core\Entity\ContentEntityInterface $data */
  $normalized = [
    'title' => $data
      ->label(),
    'link' => $this
      ->entityCanonicalUrl($data),
    'guid' => $data
      ->uuid(),
    'content:encoded' => $this->serializer
      ->normalize($data, 'fbia', $context),
  ];

  // Add author if applicable.
  if ($author = $this
    ->entityAuthor($data)) {
    $normalized['author'] = $author;
  }

  // Add created date if applicable.
  if ($created = $this
    ->entityCreatedTime($data)) {
    $normalized['created'] = $created
      ->format('c');
  }

  // Add changed date if applicable.
  if ($changed = $this
    ->entityChangedTime($data)) {
    $normalized['modified'] = $changed
      ->format('c');
  }
  return $normalized;
}