You are here

class InstantArticleRssContentEntityNormalizer 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

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

Supports the wrapping RSS scaffolding for outputting an RSS feed.

Hierarchy

Expanded class hierarchy of InstantArticleRssContentEntityNormalizer

1 file declares its use of InstantArticleRssContentEntityNormalizer
InstantArticleRssContentEntityNormalizerTest.php in tests/src/Unit/InstantArticleRssContentEntityNormalizerTest.php
1 string reference to 'InstantArticleRssContentEntityNormalizer'
fb_instant_articles.services.yml in ./fb_instant_articles.services.yml
fb_instant_articles.services.yml
1 service uses InstantArticleRssContentEntityNormalizer
serializer.fb_instant_articles.fbia_rss.content_entity in ./fb_instant_articles.services.yml
Drupal\fb_instant_articles\Normalizer\InstantArticleRssContentEntityNormalizer

File

src/Normalizer/InstantArticleRssContentEntityNormalizer.php, line 13

Namespace

Drupal\fb_instant_articles\Normalizer
View source
class InstantArticleRssContentEntityNormalizer extends NormalizerBase {
  use EntityHelperTrait;

  /**
   * {@inheritdoc}
   */
  protected $supportedInterfaceOrClass = 'Drupal\\Core\\Entity\\ContentEntityInterface';

  /**
   * {@inheritdoc}
   */
  protected $format = 'fbia_rss';

  /**
   * ContentEntityNormalizer constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config
   *   Config factory service.
   */
  public function __construct(ConfigFactoryInterface $config) {
    $this->config = $config
      ->get('fb_instant_articles.settings');
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY constant Name of key for bubbling cacheability metadata via serialization context.
EntityHelperTrait::$config protected property Instant articles config.
EntityHelperTrait::config protected function Convenience method for getting the right config object.
EntityHelperTrait::entityAuthor protected function Helper function to pull the author name out of an entity.
EntityHelperTrait::entityCanonicalUrl public function Helper function to compute the canonical URL for a given entity.
EntityHelperTrait::entityChangedTime protected function Helper function to get the changed time of the given entity if applicable.
EntityHelperTrait::entityCreatedTime protected function Helper function to get the created time of the given entity if applicable.
InstantArticleRssContentEntityNormalizer::$format protected property List of formats which supports (de-)normalization. Overrides NormalizerBase::$format
InstantArticleRssContentEntityNormalizer::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. Overrides NormalizerBase::$supportedInterfaceOrClass
InstantArticleRssContentEntityNormalizer::normalize public function
InstantArticleRssContentEntityNormalizer::__construct public function ContentEntityNormalizer constructor.
NormalizerBase::addCacheableDependency protected function Adds cacheability if applicable.
NormalizerBase::checkFormat protected function Checks if the provided format is supported by this normalizer. 1
NormalizerBase::supportsDenormalization public function Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() 1
NormalizerBase::supportsNormalization public function 1