diff --git a/src/JsonApiResource/ResourceObject.php b/src/JsonApiResource/ResourceObject.php index 599318f..662cd0b 100644 --- a/src/JsonApiResource/ResourceObject.php +++ b/src/JsonApiResource/ResourceObject.php @@ -68,7 +68,8 @@ class ResourceObject implements CacheableDependencyInterface, ResourceIdentifier * The entity to be represented by this resource object. * @param \Drupal\jsonapi\JsonApiResource\LinkCollection $links * (optional) Any links for the resource object, if a `self` link is not - * provided, one will be automatically added if the resource is locatable. + * provided, one will be automatically added if the resource is locatable + * and is not an internal entity. */ public function __construct(ResourceType $resource_type, EntityInterface $entity, LinkCollection $links = NULL) { $this->setCacheability($entity); @@ -77,7 +78,7 @@ class ResourceObject implements CacheableDependencyInterface, ResourceIdentifier $this->fields = $this->extractFields($entity); $this->resourceIdentifier = new ResourceIdentifier($resource_type, $this->entity->uuid()); $this->links = is_null($links) ? (new LinkCollection([]))->withContext($this) : $links->withContext($this); - if ($resource_type->isLocatable() && !$this->links->hasLinkWithKey('self')) { + if ($resource_type->isLocatable() && !$resource_type->isInternal() && !$this->links->hasLinkWithKey('self')) { $self_link = Url::fromRoute(Routes::getRouteName($this->getResourceType(), 'individual'), ['entity' => $this->getId()]); $this->links = $this->links->withLink('self', new Link(new CacheableMetadata(), $self_link, ['self'])); } diff --git a/tests/src/Functional/ShortcutTest.php b/tests/src/Functional/ShortcutTest.php index 26bdaf6..768c5fc 100644 --- a/tests/src/Functional/ShortcutTest.php +++ b/tests/src/Functional/ShortcutTest.php @@ -181,6 +181,7 @@ class ShortcutTest extends ResourceTestBase { 'label' => 'Alternate', ]); $alternate_shortcut_set->save(); + \Drupal::service('router.builder')->rebuildIfNeeded(); $this->entity->shortcut_set = $alternate_shortcut_set->id(); $this->entity->save();