Issue #2922487 by Wim Leers, Jo Fitzgerald, Berdir, tedbow, borisson_, dawehner, alexpott: Follow-up for #2910211: fix all deprecation warnings
parent
887e1dcd24
commit
68c0fd81dc
|
@ -179,17 +179,25 @@ class ContentEntityNormalizer extends NormalizerBase {
|
||||||
*
|
*
|
||||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||||
* The entity.
|
* The entity.
|
||||||
|
* @param array $context
|
||||||
|
* Normalization/serialization context.
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* The entity URI.
|
* The entity URI.
|
||||||
*/
|
*/
|
||||||
protected function getEntityUri(EntityInterface $entity) {
|
protected function getEntityUri(EntityInterface $entity, array $context = []) {
|
||||||
// Some entity types don't provide a canonical link template, at least call
|
// Some entity types don't provide a canonical link template, at least call
|
||||||
// out to ->url().
|
// out to ->url().
|
||||||
if ($entity->isNew() || !$entity->hasLinkTemplate('canonical')) {
|
if ($entity->isNew() || !$entity->hasLinkTemplate('canonical')) {
|
||||||
return $entity->url('canonical', []);
|
return $entity->url('canonical', []);
|
||||||
}
|
}
|
||||||
$url = $entity->urlInfo('canonical', ['absolute' => TRUE]);
|
$url = $entity->toUrl('canonical', ['absolute' => TRUE]);
|
||||||
return $url->setRouteParameter('_format', 'hal_json')->toString();
|
if (!$url->isExternal()) {
|
||||||
|
$url->setRouteParameter('_format', 'hal_json');
|
||||||
|
}
|
||||||
|
$generated_url = $url->toString(TRUE);
|
||||||
|
$this->addCacheableDependency($context, $generated_url);
|
||||||
|
return $generated_url->getGeneratedUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,8 +3,10 @@
|
||||||
namespace Drupal\hal\Normalizer;
|
namespace Drupal\hal\Normalizer;
|
||||||
|
|
||||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||||
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
use Drupal\Core\Entity\EntityManagerInterface;
|
use Drupal\Core\Entity\EntityManagerInterface;
|
||||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||||
|
use Drupal\file\FileInterface;
|
||||||
use Drupal\hal\LinkManager\LinkManagerInterface;
|
use Drupal\hal\LinkManager\LinkManagerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,4 +71,19 @@ class FileEntityNormalizer extends ContentEntityNormalizer {
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
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 file_create_url($entity->getFileUri());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,8 +55,14 @@ class EntityReferenceFieldItemNormalizer extends FieldItemNormalizer {
|
||||||
// Add a 'url' value if there is a reference and a canonical URL. Hard
|
// Add a 'url' value if there is a reference and a canonical URL. Hard
|
||||||
// code 'canonical' here as config entities override the default $rel
|
// code 'canonical' here as config entities override the default $rel
|
||||||
// parameter value to 'edit-form.
|
// parameter value to 'edit-form.
|
||||||
if ($url = $entity->url('canonical')) {
|
if ($entity->hasLinkTemplate('canonical') && $url = $entity->toUrl('canonical')->toString(TRUE)) {
|
||||||
$values['url'] = $url;
|
$this->addCacheableDependency($context, $url);
|
||||||
|
$values['url'] = $url->getGeneratedUrl();
|
||||||
|
}
|
||||||
|
// @todo Remove in https://www.drupal.org/project/drupal/issues/2925520
|
||||||
|
// @see \Drupal\hal\Normalizer\FileEntityNormalizer
|
||||||
|
elseif ($entity->getEntityTypeId() === 'file') {
|
||||||
|
$values['url'] = file_create_url($entity->getFileUri());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\serialization\Unit\Normalizer;
|
||||||
|
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||||
|
use Drupal\Core\GeneratedUrl;
|
||||||
use Drupal\Core\TypedData\Type\IntegerInterface;
|
use Drupal\Core\TypedData\Type\IntegerInterface;
|
||||||
use Drupal\Core\TypedData\TypedDataInterface;
|
use Drupal\Core\TypedData\TypedDataInterface;
|
||||||
use Drupal\Core\Entity\EntityRepositoryInterface;
|
use Drupal\Core\Entity\EntityRepositoryInterface;
|
||||||
|
@ -11,6 +12,7 @@ use Drupal\Core\Entity\FieldableEntityInterface;
|
||||||
use Drupal\Core\Field\FieldItemInterface;
|
use Drupal\Core\Field\FieldItemInterface;
|
||||||
use Drupal\Core\Field\FieldItemListInterface;
|
use Drupal\Core\Field\FieldItemListInterface;
|
||||||
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
|
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
|
||||||
|
use Drupal\Core\Url;
|
||||||
use Drupal\locale\StringInterface;
|
use Drupal\locale\StringInterface;
|
||||||
use Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer;
|
use Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer;
|
||||||
use Drupal\Tests\UnitTestCase;
|
use Drupal\Tests\UnitTestCase;
|
||||||
|
@ -106,9 +108,17 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
|
||||||
public function testNormalize() {
|
public function testNormalize() {
|
||||||
$test_url = '/test/100';
|
$test_url = '/test/100';
|
||||||
|
|
||||||
|
$generated_url = (new GeneratedUrl())->setGeneratedUrl($test_url);
|
||||||
|
|
||||||
|
$url = $this->prophesize(Url::class);
|
||||||
|
$url->toString(TRUE)
|
||||||
|
->willReturn($generated_url);
|
||||||
|
|
||||||
$entity = $this->prophesize(EntityInterface::class);
|
$entity = $this->prophesize(EntityInterface::class);
|
||||||
$entity->url('canonical')
|
$entity->hasLinkTemplate('canonical')
|
||||||
->willReturn($test_url)
|
->willReturn(TRUE);
|
||||||
|
$entity->toUrl('canonical')
|
||||||
|
->willReturn($url)
|
||||||
->shouldBeCalled();
|
->shouldBeCalled();
|
||||||
$entity->uuid()
|
$entity->uuid()
|
||||||
->willReturn('080e3add-f9d5-41ac-9821-eea55b7b42fb')
|
->willReturn('080e3add-f9d5-41ac-9821-eea55b7b42fb')
|
||||||
|
|
|
@ -125,7 +125,6 @@ trait DeprecationListenerTrait {
|
||||||
'CommentType is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d7\NodeType instead.',
|
'CommentType is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d7\NodeType instead.',
|
||||||
'CommentVariablePerCommentType is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d6\NodeType instead.',
|
'CommentVariablePerCommentType is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d6\NodeType instead.',
|
||||||
'The Drupal\migrate_drupal\Plugin\migrate\source\d6\i18nVariable is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use Drupal\migrate_drupal\Plugin\migrate\source\d6\VariableTranslation',
|
'The Drupal\migrate_drupal\Plugin\migrate\source\d6\i18nVariable is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use Drupal\migrate_drupal\Plugin\migrate\source\d6\VariableTranslation',
|
||||||
'Implicit cacheability metadata bubbling (onto the global render context) in normalizers is deprecated since Drupal 8.5.0 and will be removed in Drupal 9.0.0. Use the "cacheability" serialization context instead, for explicit cacheability metadata bubbling. See https://www.drupal.org/node/2918937',
|
|
||||||
'Adding or retrieving messages prior to the container being initialized was deprecated in Drupal 8.5.0 and this functionality will be removed before Drupal 9.0.0. Please report this usage at https://www.drupal.org/node/2928994.',
|
'Adding or retrieving messages prior to the container being initialized was deprecated in Drupal 8.5.0 and this functionality will be removed before Drupal 9.0.0. Please report this usage at https://www.drupal.org/node/2928994.',
|
||||||
'The "serializer.normalizer.file_entity.hal" normalizer service is deprecated: it is obsolete, it only remains available for backwards compatibility.',
|
'The "serializer.normalizer.file_entity.hal" normalizer service is deprecated: it is obsolete, it only remains available for backwards compatibility.',
|
||||||
'The Symfony\Component\ClassLoader\ApcClassLoader class is deprecated since Symfony 3.3 and will be removed in 4.0. Use `composer install --apcu-autoloader` instead.',
|
'The Symfony\Component\ClassLoader\ApcClassLoader class is deprecated since Symfony 3.3 and will be removed in 4.0. Use `composer install --apcu-autoloader` instead.',
|
||||||
|
|
Loading…
Reference in New Issue