CopyrightFormatter.php in Facebook Instant Articles 8.2
File
src/Plugin/Field/FieldFormatter/CopyrightFormatter.php
View source
<?php
namespace Drupal\fb_instant_articles\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Facebook\InstantArticles\Elements\Footer;
use Facebook\InstantArticles\Elements\InstantArticle;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class CopyrightFormatter extends FormatterBase {
public function viewInstantArticle(FieldItemListInterface $items, InstantArticle $article, $region, NormalizerInterface $normalizer, $langcode = NULL) {
foreach ($items as $delta => $item) {
$footer = $article
->getFooter();
if (!$footer) {
$footer = Footer::create();
$article
->withFooter($footer);
}
$copyright = $footer
->getCopyright();
if (is_string($copyright)) {
$copyright .= ' ' . $item->value;
}
else {
$copyright = $item->value;
}
$footer
->withCopyright($copyright);
}
}
}