Commit df127208 authored by catch's avatar catch

Issue #2907402 by Berdir, neel24, Wim Leers, damiankloip, tedbow: HAL...

Issue #2907402 by Berdir, neel24, Wim Leers, damiankloip, tedbow: HAL normalization of file fields don't provide file entity id or file entity REST URL
parent 5777f8f5
......@@ -60,7 +60,7 @@ protected function getExpectedNormalizedEntity() {
],
'_links' => [
'self' => [
'href' => '',
'href' => $this->baseUrl . '/entity/aggregator_item/1?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/aggregator_item/aggregator_item',
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Entity\EntityTypeRepositoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\TypedData\TypedDataInternalPropertiesHelper;
use Drupal\Core\Url;
use Drupal\hal\LinkManager\LinkManagerInterface;
use Drupal\serialization\Normalizer\FieldableEntityNormalizerTrait;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
......@@ -198,10 +199,22 @@ public function denormalize($data, $class, $format = NULL, array $context = [])
*/
protected function getEntityUri(EntityInterface $entity, array $context = []) {
// Some entity types don't provide a canonical link template.
if ($entity->isNew() || !$entity->hasLinkTemplate('canonical')) {
if ($entity->isNew()) {
return '';
}
$url = $entity->toUrl('canonical', ['absolute' => TRUE]);
$route_name = 'rest.entity.' . $entity->getEntityTypeId() . '.GET';
if ($entity->hasLinkTemplate('canonical')) {
$url = $entity->toUrl('canonical');
}
elseif (\Drupal::service('router.route_provider')->getRoutesByNames([$route_name])) {
$url = Url::fromRoute('rest.entity.' . $entity->getEntityTypeId() . '.GET', [$entity->getEntityTypeId() => $entity->id()]);
}
else {
return '';
}
$url->setAbsolute(TRUE);
if (!$url->isExternal()) {
$url->setRouteParameter('_format', 'hal_json');
}
......
......@@ -49,6 +49,19 @@ public function setUp() {
->set('standalone_url', TRUE)
->save(TRUE);
// Provisioning the Media REST resource without the File REST resource does
// not make sense.
$this->resourceConfigStorage->create([
'id' => 'entity.file',
'granularity' => RestResourceConfigInterface::RESOURCE_GRANULARITY,
'configuration' => [
'methods' => ['GET'],
'formats' => [static::$format],
'authentication' => isset(static::$auth) ? [static::$auth] : [],
],
'status' => TRUE,
])->save();
$this->container->get('router.builder')->rebuild();
}
......
......@@ -21,7 +21,7 @@ protected function getExpectedNormalizedEntity() {
return $normalization + [
'_links' => [
'self' => [
'href' => '',
'href' => $this->baseUrl . '/entity/path_alias/1?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/path_alias/path_alias',
......
......@@ -141,6 +141,19 @@ public function setUp() {
'status' => TRUE,
])->save();
// Provisioning the file upload REST resource without the File REST resource
// does not make sense.
$this->resourceConfigStorage->create([
'id' => 'entity.file',
'granularity' => RestResourceConfigInterface::RESOURCE_GRANULARITY,
'configuration' => [
'methods' => ['GET'],
'formats' => [static::$format],
'authentication' => isset(static::$auth) ? [static::$auth] : [],
],
'status' => TRUE,
])->save();
$this->refreshTestStateAfterRestConfigChange();
}
......
......@@ -47,7 +47,7 @@ protected function getExpectedNormalizedEntity() {
return $normalization + [
'_links' => [
'self' => [
'href' => '',
'href' => $this->baseUrl . '/entity/entity_test_label/1?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/entity_test_label/entity_test_label',
......
......@@ -47,7 +47,7 @@ protected function getExpectedNormalizedEntity() {
return $normalization + [
'_links' => [
'self' => [
'href' => '',
'href' => $this->baseUrl . '/entity/entity_test_map_field/1?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/entity_test_map_field/entity_test_map_field',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment