public \Tobscure\JsonApi\Relationship|void
getRelationship
(mixed $model, mixed $name)
/**
* Get a relationship.
*
* @param mixed $model The model of the entity being rendered
* @param string $name The name of the relationship to return
*
* @return \Tobscure\JsonApi\Relationship|void
*
* @since 4.0.0
*/
public function getRelationship($model, $name)
{
$result = parent::getRelationship($model, $name);
// If we found a result in the content type serializer return now. Else trigger plugins.
if ($result instanceof Relationship) {
return $result;
}
$eventData = ['model' => $model, 'field' => $name, 'context' => $this->type];
$event = new Events\OnGetApiRelation('onGetApiRelation', $eventData);
/** @var Events\OnGetApiRelation $eventResult */
$eventResult = Factory::getApplication()->getDispatcher()->dispatch('onGetApiRelation', $event);
$relationship = $eventResult->getRelationship();
if ($relationship instanceof Relationship) {
return $relationship;
}
}