You are here

protected function FileEntityNormalizer::getEntityUri in Drupal 8

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

Constructs the entity URI.

Parameters

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

array $context: Normalization/serialization context.

Return value

string The entity URI.

Overrides ContentEntityNormalizer::getEntityUri

1 call to FileEntityNormalizer::getEntityUri()
FileEntityNormalizer::normalize in core/modules/hal/src/Normalizer/FileEntityNormalizer.php

File

core/modules/hal/src/Normalizer/FileEntityNormalizer.php, line 84

Class

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

Namespace

Drupal\hal\Normalizer

Code

protected function getEntityUri(EntityInterface $entity, array $context = []) {
  assert($entity instanceof FileInterface);

  // https://www.drupal.org/project/drupal/issues/2277705 introduced a hack
  // in \Drupal\file\Entity\File::url(), but EntityInterface::url() was
  // deprecated in favor of ::toUrl(). The parent implementation now calls
  // ::toUrl(), but this normalizer (for File entities) needs to override that
  // back to the old behavior because it relies on said hack, not just to
  // generate the value for the 'uri' field of a file (see ::normalize()), but
  // also for the HAL normalization's '_links' value.
  return $entity
    ->createFileUrl(FALSE);
}