You are here

public function LinkManager::getEntityLink in JSON:API 8

Gets a link for the entity.

Parameters

int $entity_id: The entity ID to generate the link for. Note: Depending on the configuration this might be the UUID as well.

\Drupal\jsonapi\ResourceType\ResourceType $resource_type: The JSON API resource type.

array $route_parameters: Parameters for the route generation.

string $key: A key to build the route identifier.

Return value

string|null The URL string, or NULL if the given entity is not locatable.

File

src/LinkManager/LinkManager.php, line 57

Class

LinkManager
Class to generate links and queries for entities.

Namespace

Drupal\jsonapi\LinkManager

Code

public function getEntityLink($entity_id, ResourceType $resource_type, array $route_parameters, $key) {
  if (!$resource_type
    ->isLocatable()) {
    return NULL;
  }
  $route_parameters += [
    $resource_type
      ->getEntityTypeId() => $entity_id,
  ];
  $route_key = sprintf('jsonapi.%s.%s', $resource_type
    ->getTypeName(), $key);
  return $this->urlGenerator
    ->generateFromRoute($route_key, $route_parameters, [
    'absolute' => TRUE,
  ], TRUE)
    ->getGeneratedUrl();
}