diff --git a/system/src/Grav/Framework/Contracts/Relationships/ToManyRelationshipInterface.php b/system/src/Grav/Framework/Contracts/Relationships/ToManyRelationshipInterface.php index 4ad5af1da..723bef690 100644 --- a/system/src/Grav/Framework/Contracts/Relationships/ToManyRelationshipInterface.php +++ b/system/src/Grav/Framework/Contracts/Relationships/ToManyRelationshipInterface.php @@ -13,6 +13,12 @@ use Grav\Framework\Contracts\Object\IdentifierInterface; */ interface ToManyRelationshipInterface extends RelationshipInterface { + /** + * @param positive-int $pos + * @return IdentifierInterface|null + */ + public function getNthIdentifier(int $pos): ?IdentifierInterface; + /** * @param string $id * @param string|null $type diff --git a/system/src/Grav/Framework/Relationships/ToManyRelationship.php b/system/src/Grav/Framework/Relationships/ToManyRelationship.php index 73dbc6cce..26b138e43 100644 --- a/system/src/Grav/Framework/Relationships/ToManyRelationship.php +++ b/system/src/Grav/Framework/Relationships/ToManyRelationship.php @@ -88,6 +88,21 @@ class ToManyRelationship implements ToManyRelationshipInterface return $this->getIdentifier($id, $type) !== null; } + /** + * @param positive-int $pos + * @return IdentifierInterface|null + */ + public function getNthIdentifier(int $pos): ?IdentifierInterface + { + $items = array_keys($this->identifiers); + $key = $items[$pos - 1] ?? null; + if (null === $key) { + return null; + } + + return $this->identifiers[$key] ?? null; + } + /** * @param string $id * @param string|null $type