Skip to content

Commit

Permalink
fix: handle item iri with identifiers in LegacyIriConverter (#5670)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
jonnyeom and dunglas authored Aug 1, 2023
1 parent c1b4e5a commit deed442
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Core/Api/LegacyIriConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Api\UrlGeneratorInterface;
use ApiPlatform\Core\Api\IriConverterInterface as LegacyIriConverterInterface;
use ApiPlatform\Exception\InvalidArgumentException;
use ApiPlatform\Metadata\Operation;

/**
Expand Down Expand Up @@ -64,6 +65,14 @@ public function getResourceFromIri(string $iri, array $context = [], ?Operation
public function getIriFromResource($item, int $referenceType = UrlGeneratorInterface::ABS_PATH, Operation $operation = null, array $context = []): ?string
{
if (null === $this->iriConverter) {
if ($identifiers = ($context['uri_variables'] ?? null)) {
try {
return $this->legacyIriConverter->getItemIriFromResourceClass($item, $identifiers, $referenceType);
}
catch (InvalidArgumentException $e) {
}
}

return \is_string($item) ? $this->legacyIriConverter->getIriFromResourceClass($item, $referenceType) : $this->legacyIriConverter->getIriFromItem($item, $referenceType);
}

Expand Down

0 comments on commit deed442

Please sign in to comment.