core/modules/file/src/Entity/File.php | 31 ---------------------- .../hal/src/Normalizer/ContentEntityNormalizer.php | 2 +- .../hal/src/Normalizer/FileEntityNormalizer.php | 13 +++++++++ 3 files changed, 14 insertions(+), 32 deletions(-) diff --git a/core/modules/file/src/Entity/File.php b/core/modules/file/src/Entity/File.php index b7d09d4..33f6d74 100644 --- a/core/modules/file/src/Entity/File.php +++ b/core/modules/file/src/Entity/File.php @@ -7,7 +7,6 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; -use Drupal\Core\Url; use Drupal\file\FileInterface; use Drupal\user\UserInterface; @@ -79,42 +78,12 @@ public function setFileUri($uri) { * @see file_url_transform_relative() */ public function url($rel = 'canonical', $options = []) { - // @todo Remove this work-around before Drupal 9.0.0. This was introduced as - // a temporary work-around in https://www.drupal.org/node/2277705 to provide - // REST support for file entities. https://www.drupal.org/node/2825487 made - // this obsolete. return file_create_url($this->getFileUri()); } /** * {@inheritdoc} */ - public function toUrl($rel = 'canonical', array $options = []) { - // To not break BC, the old behavior is retained for 'canonical'. - // @see ::url() - // @todo Remove in Drupoal 9.0.0. - if ($rel === 'canonical') { - return Url::fromUri($this->url()); - } - return parent::toUrl($rel, $options); - } - - /** - * {@inheritdoc} - */ - public function hasLinkTemplate($rel) { - // To not break BC, the old behavior is retained for 'canonical'. - // @see ::url() - // @todo Remove in Drupoal 9.0.0. - if ($rel === 'canonical') { - return TRUE; - } - return parent::hasLinkTemplate($rel); - } - - /** - * {@inheritdoc} - */ public function getMimeType() { return $this->get('filemime')->value; } diff --git a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php index c41029b..1ba859e 100644 --- a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php +++ b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php @@ -191,7 +191,7 @@ protected function getEntityUri(EntityInterface $entity, array $context = []) { if ($entity->isNew() || !$entity->hasLinkTemplate('canonical')) { return $entity->url('canonical', []); } - $url = $entity->urlInfo('canonical', ['absolute' => TRUE]); + $url = $entity->toUrl('canonical', ['absolute' => TRUE]); if (!$url->isExternal()) { $url->setRouteParameter('_format', 'hal_json'); } diff --git a/core/modules/hal/src/Normalizer/FileEntityNormalizer.php b/core/modules/hal/src/Normalizer/FileEntityNormalizer.php index 5aaed3c..f9c7670 100644 --- a/core/modules/hal/src/Normalizer/FileEntityNormalizer.php +++ b/core/modules/hal/src/Normalizer/FileEntityNormalizer.php @@ -3,6 +3,7 @@ namespace Drupal\hal\Normalizer; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\hal\LinkManager\LinkManagerInterface; @@ -69,4 +70,16 @@ public function normalize($entity, $format = NULL, array $context = []) { return $data; } + /** + * {@inheritdoc} + */ + protected function getEntityUri(EntityInterface $entity, array $context = []) { + // 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. + return $entity->url('canonical', []); + } + }