You are here

protected function ContentEntityNormalizer::getEntityUri in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/hal/src/Normalizer/ContentEntityNormalizer.php \Drupal\hal\Normalizer\ContentEntityNormalizer::getEntityUri()

Constructs the entity URI.

Parameters

\Drupal\Core\Entity\EntityInterface: The entity.

Return value

string The entity URI.

2 calls to ContentEntityNormalizer::getEntityUri()
ContentEntityNormalizer::normalize in core/modules/hal/src/Normalizer/ContentEntityNormalizer.php
Normalizes an object into a set of arrays/scalars.
FileEntityNormalizer::normalize in core/modules/hal/src/Normalizer/FileEntityNormalizer.php
Normalizes an object into a set of arrays/scalars.

File

core/modules/hal/src/Normalizer/ContentEntityNormalizer.php, line 204
Contains \Drupal\hal\Normalizer\ContentEntityNormalizer.

Class

ContentEntityNormalizer
Converts the Drupal entity object structure to a HAL array structure.

Namespace

Drupal\hal\Normalizer

Code

protected function getEntityUri(EntityInterface $entity) {

  // Some entity types don't provide a canonical link template, at least call
  // out to ->url().
  if ($entity
    ->isNew() || !$entity
    ->hasLinkTemplate('canonical')) {
    return $entity
      ->url('canonical', []);
  }
  $url = $entity
    ->urlInfo('canonical', [
    'absolute' => TRUE,
  ]);
  return $url
    ->setRouteParameter('_format', 'hal_json')
    ->toString();
}