class EntityReferenceFieldItemNormalizer in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer
Adds the file URI to embedded file entities.
Hierarchy
- class \Symfony\Component\Serializer\Normalizer\SerializerAwareNormalizer implements SerializerAwareInterface
- class \Drupal\serialization\Normalizer\NormalizerBase implements NormalizerInterface
- class \Drupal\serialization\Normalizer\ComplexDataNormalizer
- class \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer
- class \Drupal\serialization\Normalizer\ComplexDataNormalizer
- class \Drupal\serialization\Normalizer\NormalizerBase implements NormalizerInterface
Expanded class hierarchy of EntityReferenceFieldItemNormalizer
1 file declares its use of EntityReferenceFieldItemNormalizer
- EntityReferenceFieldItemNormalizerTest.php in core/
modules/ serialization/ tests/ src/ Unit/ Normalizer/ EntityReferenceFieldItemNormalizerTest.php - Contains \Drupal\Tests\serialization\Unit\Normalizer\EntityReferenceFieldItemNormalizerTest.
1 string reference to 'EntityReferenceFieldItemNormalizer'
- serialization.services.yml in core/
modules/ serialization/ serialization.services.yml - core/modules/serialization/serialization.services.yml
1 service uses EntityReferenceFieldItemNormalizer
File
- core/
modules/ serialization/ src/ Normalizer/ EntityReferenceFieldItemNormalizer.php, line 15 - Contains \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer.
Namespace
Drupal\serialization\NormalizerView source
class EntityReferenceFieldItemNormalizer extends ComplexDataNormalizer {
/**
* The interface or class that this Normalizer supports.
*
* @var string
*/
protected $supportedInterfaceOrClass = EntityReferenceItem::class;
/**
* {@inheritdoc}
*/
public function normalize($field_item, $format = NULL, array $context = []) {
$values = parent::normalize($field_item, $format, $context);
// Add a 'url' value if there is a reference and a canonical URL. Hard code
// 'canonical' here as config entities override the default $rel parameter
// value to 'edit-form.
/** @var \Drupal\Core\Entity\EntityInterface $entity */
if (($entity = $field_item
->get('entity')
->getValue()) && ($url = $entity
->url('canonical'))) {
$values['url'] = $url;
}
return $values;
}
}