Skip to content

Commit 647370a

Browse files
committed
Make sure links retain the correct collection context
1 parent 68891a5 commit 647370a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Serializer.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,18 @@ private function addToMap(Context $context): array
6363
foreach ($context->endpoints($collection) as $endpoint) {
6464
if ($endpoint instanceof ProvidesResourceLinks) {
6565
foreach ($endpoint->resourceLinks($collectionContext) as $field) {
66-
$linkFieldsCache[$type][$field->name] ??= $field;
66+
$linkFieldsCache[$type][$field->name] ??= [
67+
$field,
68+
$collectionContext,
69+
];
6770
}
6871
}
6972
}
7073
}
7174
}
7275

73-
foreach ($linkFieldsCache[$type] ?? [] as $field) {
74-
if (!$field->isVisible($linkContext = $context->withField($field))) {
76+
foreach ($linkFieldsCache[$type] ?? [] as [$field, $collectionContext]) {
77+
if (!$field->isVisible($linkContext = $collectionContext->withField($field))) {
7578
continue;
7679
}
7780

0 commit comments

Comments
 (0)