You are here

public function TypeLinkManager::getTypeUri in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/hal/src/LinkManager/TypeLinkManager.php \Drupal\hal\LinkManager\TypeLinkManager::getTypeUri()

Gets the URI that corresponds to a bundle.

When using hypermedia formats, this URI can be used to indicate which bundle the data represents. Documentation about required and optional fields can also be provided at this URI.

Parameters

$entity_type: The bundle's entity type.

$bundle: The bundle name.

array $context: (optional) Optional serializer/normalizer context.

Return value

string The corresponding URI for the bundle.

Overrides TypeLinkManagerInterface::getTypeUri

1 call to TypeLinkManager::getTypeUri()
TypeLinkManager::writeCache in core/modules/hal/src/LinkManager/TypeLinkManager.php
Writes the cache of type links.

File

core/modules/hal/src/LinkManager/TypeLinkManager.php, line 72

Class

TypeLinkManager

Namespace

Drupal\hal\LinkManager

Code

public function getTypeUri($entity_type, $bundle, $context = []) {

  // Per the interface documentation of this method, the returned URI may
  // optionally also serve as the URL of a documentation page about this
  // bundle. However, Drupal does not currently implement such a documentation
  // page. Therefore, we return a URI assembled relative to the site's base
  // URL, which is sufficient to uniquely identify the site's entity type and
  // bundle for use in hypermedia formats, but we do not take into account
  // unclean URLs, language prefixing, or anything else that would be required
  // for Drupal to be able to respond with content at this URL. If a module is
  // installed that adds such content, but requires this URL to be different
  // (e.g., include a language prefix), then the module must also override the
  // TypeLinkManager class/service to return the desired URL.
  $uri = $this
    ->getLinkDomain($context) . "/rest/type/{$entity_type}/{$bundle}";
  $this->moduleHandler
    ->alter('hal_type_uri', $uri, $context);
  return $uri;
}