mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
Added ToManyRelationship::getNthIdentifier()
This commit is contained in:
parent
1237f0a6d6
commit
32a486f1d4
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user