You are here

public function InstantArticleContentEntityNormalizer::normalizeDefaultHeader in Facebook Instant Articles 3.x

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

Normalize the default header of the instant article.

Use known properties of the content entity to normalize default properties of the instant article header.

Parameters

\Facebook\InstantArticles\Elements\InstantArticle $article: Instant article object we are normalizing to.

\Drupal\Core\Entity\ContentEntityInterface $entity: Content entity being normalized.

Return value

\Facebook\InstantArticles\Elements\InstantArticle Modified instant article.

1 call to InstantArticleContentEntityNormalizer::normalizeDefaultHeader()
InstantArticleContentEntityNormalizer::normalize in src/Normalizer/InstantArticleContentEntityNormalizer.php

File

src/Normalizer/InstantArticleContentEntityNormalizer.php, line 227

Class

InstantArticleContentEntityNormalizer
Facebook Instant Articles content entity normalizer.

Namespace

Drupal\fb_instant_articles\Normalizer

Code

public function normalizeDefaultHeader(InstantArticle $article, ContentEntityInterface $entity) {
  $header = $article
    ->getHeader();
  if (!$header) {
    $header = Header::create();
    $article
      ->withHeader($header);
  }
  if ($label = $entity
    ->label()) {
    $header
      ->withTitle($label);
  }

  // Set a created date if available.
  if ($created = $this
    ->entityCreatedTime($entity)) {
    $header
      ->withPublishTime(Time::create(Time::PUBLISHED)
      ->withDatetime($created));
  }

  // Set a changed date if available.
  if ($changed = $this
    ->entityChangedTime($entity)) {
    $header
      ->withModifyTime(Time::create(Time::MODIFIED)
      ->withDatetime($changed));
  }

  // Default the article author to the username.
  if ($author = $this
    ->entityAuthor($entity)) {
    $header
      ->addAuthor(Author::create()
      ->withName($author));
  }
  return $article;
}