class MetatagNormalizer in Metatag 8
Normalizes metatag into the viewed entity.
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\metatag\Normalizer\MetatagNormalizer
Expanded class hierarchy of MetatagNormalizer
1 file declares its use of MetatagNormalizer
File
- src/
Normalizer/ MetatagNormalizer.php, line 10
Namespace
Drupal\metatag\NormalizerView source
class MetatagNormalizer extends NormalizerBase {
/**
* {@inheritdoc}
*/
protected $supportedInterfaceOrClass = 'Drupal\\metatag\\Plugin\\Field\\MetatagEntityFieldItemList';
/**
* {@inheritdoc}
*/
public function normalize($field_item, $format = NULL, array $context = []) {
// @see metatag_get_tags_from_route()
$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) {
// @todo Work out a proper, long-term fix for this.
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;
}
/**
* {@inheritdoc}
*/
public function supportsDenormalization($data, $type, $format = NULL) {
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableNormalizerInterface:: |
constant | Name of key for bubbling cacheability metadata via serialization context. | ||
MetatagNormalizer:: |
protected | property |
The interface or class that this Normalizer supports. Overrides NormalizerBase:: |
|
MetatagNormalizer:: |
public | function | Normalizes an object into a set of arrays/scalars. | 1 |
MetatagNormalizer:: |
public | function |
Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() Overrides NormalizerBase:: |
|
NormalizerBase:: |
protected | property | List of formats which supports (de-)normalization. | 3 |
NormalizerBase:: |
protected | function | Adds cacheability if applicable. | |
NormalizerBase:: |
protected | function | Checks if the provided format is supported by this normalizer. | 2 |
NormalizerBase:: |
public | function | Checks whether the given class is supported for normalization by this normalizer. | 1 |