InstantArticleRssContentEntityNormalizer.php in Facebook Instant Articles 3.x
File
src/Normalizer/InstantArticleRssContentEntityNormalizer.php
View source
<?php
namespace Drupal\fb_instant_articles\Normalizer;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\serialization\Normalizer\NormalizerBase;
class InstantArticleRssContentEntityNormalizer extends NormalizerBase {
use EntityHelperTrait;
protected $supportedInterfaceOrClass = 'Drupal\\Core\\Entity\\ContentEntityInterface';
protected $format = 'fbia_rss';
public function __construct(ConfigFactoryInterface $config) {
$this->config = $config
->get('fb_instant_articles.settings');
}
public function normalize($data, $format = NULL, array $context = []) {
$normalized = [
'title' => $data
->label(),
'link' => $this
->entityCanonicalUrl($data),
'guid' => $data
->uuid(),
'content:encoded' => $this->serializer
->normalize($data, 'fbia', $context),
];
if ($author = $this
->entityAuthor($data)) {
$normalized['author'] = $author;
}
if ($created = $this
->entityCreatedTime($data)) {
$normalized['created'] = $created
->format('c');
}
if ($changed = $this
->entityChangedTime($data)) {
$normalized['modified'] = $changed
->format('c');
}
return $normalized;
}
}