Skip to content

Commit deed442

Browse files
jonnyeomdunglas
andauthored
fix: handle item iri with identifiers in LegacyIriConverter (#5670)
* fix: handle item iri with identifiers in LegacyIriConverter * fix: syntax for null and falsy check Co-authored-by: Kévin Dunglas <[email protected]> --------- Co-authored-by: Kévin Dunglas <[email protected]>
1 parent c1b4e5a commit deed442

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Core/Api/LegacyIriConverter.php

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Api\IriConverterInterface;
1717
use ApiPlatform\Api\UrlGeneratorInterface;
1818
use ApiPlatform\Core\Api\IriConverterInterface as LegacyIriConverterInterface;
19+
use ApiPlatform\Exception\InvalidArgumentException;
1920
use ApiPlatform\Metadata\Operation;
2021

2122
/**
@@ -64,6 +65,14 @@ public function getResourceFromIri(string $iri, array $context = [], ?Operation
6465
public function getIriFromResource($item, int $referenceType = UrlGeneratorInterface::ABS_PATH, Operation $operation = null, array $context = []): ?string
6566
{
6667
if (null === $this->iriConverter) {
68+
if ($identifiers = ($context['uri_variables'] ?? null)) {
69+
try {
70+
return $this->legacyIriConverter->getItemIriFromResourceClass($item, $identifiers, $referenceType);
71+
}
72+
catch (InvalidArgumentException $e) {
73+
}
74+
}
75+
6776
return \is_string($item) ? $this->legacyIriConverter->getIriFromResourceClass($item, $referenceType) : $this->legacyIriConverter->getIriFromItem($item, $referenceType);
6877
}
6978

0 commit comments

Comments
 (0)