public function EntityReferenceFieldItemNormalizer::normalize in Content Synchronization 3.0.x
Same name and namespace in other branches
- 8.2 src/Normalizer/EntityReferenceFieldItemNormalizer.php \Drupal\content_sync\Normalizer\EntityReferenceFieldItemNormalizer::normalize()
Overrides ComplexDataNormalizer::normalize
File
- src/
Normalizer/ EntityReferenceFieldItemNormalizer.php, line 45
Class
- EntityReferenceFieldItemNormalizer
- Adds the file URI to embedded file entities.
Namespace
Drupal\content_sync\NormalizerCode
public function normalize($field_item, $format = NULL, array $context = []) {
$values = parent::normalize($field_item, $format, $context);
/** @var \Drupal\Core\Entity\EntityInterface $entity */
if ($entity = $field_item
->get('entity')
->getValue()) {
$values['target_type'] = $entity
->getEntityTypeId();
// Add the target entity UUID to the normalized output values.
$values['target_uuid'] = $entity
->uuid();
// Remove target revision id as we are not syncing revisions.
if (isset($values['target_revision_id'])) {
unset($values['target_revision_id']);
}
// 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.
if ($entity
->hasLinkTemplate('canonical')) {
$url = $entity
->toUrl('canonical')
->toString();
$values['url'] = $url;
}
}
return $values;
}