Skip to content
Snippets Groups Projects

Fix issue with multiple entity references

Merged Claudiu Cristea requested to merge issue/rdf_sync-3438180:3438180-ref into 1.x
1 unresolved thread
Files
6
@@ -70,7 +70,7 @@ public function normalize($object, $format = NULL, array $context = []): array {
}
foreach ($normalized as $fieldName => $items) {
foreach ($items as $item) {
foreach ($items as $delta => $item) {
foreach ($item as $columnName => $value) {
if (!$mapping = ($mappings[$fieldName][$columnName] ?? NULL)) {
// This column is not mapped.
@@ -87,17 +87,19 @@ public function normalize($object, $format = NULL, array $context = []): array {
$value = $rdfType;
}
}
// Resolve references to other entities.
elseif (is_a(EntityReferenceItem::class, $itemDefinition->getClass(), TRUE)) {
/** @var \Drupal\Core\Entity\EntityInterface $entity */
if (!$entity = $object->get($fieldName)->entity) {
Please register or sign in to reply
// Resolve references to other entities. Cover also field types that
// are extending entity reference.
elseif ($columnName === 'target_id' && is_a($itemDefinition->getClass(), EntityReferenceItem::class, TRUE)) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $targetEntity */
$targetEntity = $object->get($fieldName)->get($delta)->entity;
if (!$targetEntity) {
$value = NULL;
}
elseif ($this->mapper->isMappedEntity($entity)) {
elseif ($this->mapper->isMappedEntity($targetEntity)) {
// If the destination is also mapped, replace the scalar ID (int,
// string) with the URI.
$targetUriFieldName = $this->mapper->getRdfUriFieldName(entity: $entity);
$value = $object->get($fieldName)->entity->get($targetUriFieldName)->value;
$targetUriFieldName = $this->mapper->getRdfUriFieldName(entity: $targetEntity);
$value = $targetEntity->get($targetUriFieldName)->value;
}
}
Loading