public function EntityReferenceFieldItemNormalizer::normalize in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer::normalize()
Normalizes an object into a set of arrays/scalars.
Parameters
object $object object to normalize:
string $format format the normalization result will be encoded as:
array $context Context options for the normalizer:
Return value
array|string|bool|int|float|null
Overrides ComplexDataNormalizer::normalize
File
- core/
modules/ serialization/ src/ Normalizer/ EntityReferenceFieldItemNormalizer.php, line 27 - Contains \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer.
Class
- EntityReferenceFieldItemNormalizer
- Adds the file URI to embedded file entities.
Namespace
Drupal\serialization\NormalizerCode
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;
}