class InstantArticleRssContentEntityNormalizer in Facebook Instant Articles 8.2
Same name and namespace in other branches
- 3.x 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
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\fb_instant_articles\Normalizer\InstantArticleRssContentEntityNormalizer uses EntityHelperTrait
Expanded class hierarchy of InstantArticleRssContentEntityNormalizer
1 file declares its use of InstantArticleRssContentEntityNormalizer
1 string reference to 'InstantArticleRssContentEntityNormalizer'
1 service uses InstantArticleRssContentEntityNormalizer
File
- src/
Normalizer/ InstantArticleRssContentEntityNormalizer.php, line 13
Namespace
Drupal\fb_instant_articles\NormalizerView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableNormalizerInterface:: |
constant | Name of key for bubbling cacheability metadata via serialization context. | ||
EntityHelperTrait:: |
protected | property | Instant articles config. | |
EntityHelperTrait:: |
protected | function | Convenience method for getting the right config object. | |
EntityHelperTrait:: |
protected | function | Helper function to pull the author name out of an entity. | |
EntityHelperTrait:: |
public | function | Helper function to compute the canonical URL for a given entity. | |
EntityHelperTrait:: |
protected | function | Helper function to get the changed time of the given entity if applicable. | |
EntityHelperTrait:: |
protected | function | Helper function to get the created time of the given entity if applicable. | |
InstantArticleRssContentEntityNormalizer:: |
protected | property |
List of formats which supports (de-)normalization. Overrides NormalizerBase:: |
|
InstantArticleRssContentEntityNormalizer:: |
protected | property |
The interface or class that this Normalizer supports. Overrides NormalizerBase:: |
|
InstantArticleRssContentEntityNormalizer:: |
public | function | ||
InstantArticleRssContentEntityNormalizer:: |
public | function | ContentEntityNormalizer constructor. | |
NormalizerBase:: |
protected | function | Adds cacheability if applicable. | |
NormalizerBase:: |
protected | function | Checks if the provided format is supported by this normalizer. | 2 |
NormalizerBase:: |
public | function | Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() | 1 |
NormalizerBase:: |
public | function | Checks whether the given class is supported for normalization by this normalizer. | 1 |