MetatagNormalizer.php in Metatag 8
File
src/Normalizer/MetatagNormalizer.php
View source
<?php
namespace Drupal\metatag\Normalizer;
use Drupal\serialization\Normalizer\NormalizerBase;
class MetatagNormalizer extends NormalizerBase {
protected $supportedInterfaceOrClass = 'Drupal\\metatag\\Plugin\\Field\\MetatagEntityFieldItemList';
public function normalize($field_item, $format = NULL, array $context = []) {
$entity = $field_item
->getEntity();
$tags = metatag_get_tags_from_route($entity);
$normalized['value'] = [];
if (isset($tags['#attached']['html_head'])) {
foreach ($tags['#attached']['html_head'] as $tag) {
if (isset($tag[0]['#attributes']['content'])) {
$normalized['value'][$tag[1]] = $tag[0]['#attributes']['content'];
}
elseif (isset($tag[0]['#attributes']['href'])) {
$normalized['value'][$tag[1]] = $tag[0]['#attributes']['href'];
}
}
}
if (isset($context['langcode'])) {
$normalized['lang'] = $context['langcode'];
}
return $normalized;
}
public function supportsDenormalization($data, $type, $format = NULL) {
return FALSE;
}
}