diff --git a/src/Plugin/jsonapi/FieldEnhancer/UuidLinkEnhancer.php b/src/Plugin/jsonapi/FieldEnhancer/UuidLinkEnhancer.php index c86ba76..c76be9e 100644 --- a/src/Plugin/jsonapi/FieldEnhancer/UuidLinkEnhancer.php +++ b/src/Plugin/jsonapi/FieldEnhancer/UuidLinkEnhancer.php @@ -12,7 +12,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * * @ResourceFieldEnhancer( * id = "uuid_link", - * label = @Translation("UUID for link"), + * label = @Translation("UUID for link (link field only)"), * description = @Translation("Use UUID for internal link field.") * ) */ @@ -56,7 +56,17 @@ class UuidLinkEnhancer extends ResourceFieldEnhancerBase implements ContainerFac $entity_type = $parsed_uri[1]; $entity_id = $parsed_uri[2]; $entity = $this->entityTypeManager->getStorage($entity_type)->load($entity_id); - $value['uri'] = 'entity:' . $entity_type . '/' . $entity->bundle() . '/' . $entity->uuid(); + if (!is_null($entity)) { + $value['uri'] = 'entity:' . $entity_type . '/' . $entity->bundle() . '/' . $entity->uuid(); + } + // Remove the value. + else { + $value = [ + 'uri' => '', + 'title' => '', + 'options' => [], + ]; + } } }