diff --git a/core/modules/hal/lib/Drupal/hal/Normalizer/EntityCollectionNormalizer.php b/core/modules/hal/lib/Drupal/hal/Normalizer/EntityCollectionNormalizer.php index dbc302d..05e5dfc 100644 --- a/core/modules/hal/lib/Drupal/hal/Normalizer/EntityCollectionNormalizer.php +++ b/core/modules/hal/lib/Drupal/hal/Normalizer/EntityCollectionNormalizer.php @@ -38,8 +38,8 @@ public function normalize($object, $format = NULL, array $context = array()) { // Add the list of items. foreach ($object->getItems() as $item) { - // @todo Figure out a way to use an appropriate link relation here. - $normalized['_embedded']['temporary_link_relation'][] = $this->serializer->normalize($item, $format, $context); + $link_relation = $this->linkManager->getCollectionItemRelation($object->getCollectionId()); + $normalized['_embedded'][$link_relation][] = $this->serializer->normalize($item, $format, $context); } return $normalized; diff --git a/core/modules/rest/lib/Drupal/rest/LinkManager/CollectionLinkManager.php b/core/modules/rest/lib/Drupal/rest/LinkManager/CollectionLinkManager.php new file mode 100644 index 0000000..3097f3b --- /dev/null +++ b/core/modules/rest/lib/Drupal/rest/LinkManager/CollectionLinkManager.php @@ -0,0 +1,23 @@ +typeLinkManager = $type_link_manager; $this->relationLinkManager = $relation_link_manager; + $this->collectionLinkManager = $collection_link_manager; } /** @@ -62,4 +72,11 @@ public function getRelationUri($entity_type, $bundle, $field_name) { public function getRelationInternalIds($relation_uri) { return $this->relationLinkManager->getRelationInternalIds($relation_uri); } + + /** + * {@inheritdoc} + */ + public function getCollectionItemRelation($collection_id) { + return $this->collectionLinkManager->getCollectionItemRelation($collection_id); + } } diff --git a/core/modules/rest/lib/Drupal/rest/LinkManager/LinkManagerInterface.php b/core/modules/rest/lib/Drupal/rest/LinkManager/LinkManagerInterface.php index 60e5629..c9fd834 100644 --- a/core/modules/rest/lib/Drupal/rest/LinkManager/LinkManagerInterface.php +++ b/core/modules/rest/lib/Drupal/rest/LinkManager/LinkManagerInterface.php @@ -16,8 +16,8 @@ * extending all of the component ones. * * While a link manager may directly implement these interface methods with - * custom logic, it is expected to be more common for plugin managers to proxy + * custom logic, it is expected to be more common for link managers to proxy * the method invocations to the respective components. */ -interface LinkManagerInterface extends TypeLinkManagerInterface, RelationLinkManagerInterface { +interface LinkManagerInterface extends TypeLinkManagerInterface, RelationLinkManagerInterface, CollectionLinkManagerInterface { } diff --git a/core/modules/rest/rest.services.yml b/core/modules/rest/rest.services.yml index d238442..16afb28 100644 --- a/core/modules/rest/rest.services.yml +++ b/core/modules/rest/rest.services.yml @@ -20,10 +20,12 @@ services: - { name: access_check } rest.link_manager: class: Drupal\rest\LinkManager\LinkManager - arguments: ['@rest.link_manager.type', '@rest.link_manager.relation'] + arguments: ['@rest.link_manager.type', '@rest.link_manager.relation', '@rest.link_manager.collection'] rest.link_manager.type: class: Drupal\rest\LinkManager\TypeLinkManager arguments: ['@cache.cache'] rest.link_manager.relation: class: Drupal\rest\LinkManager\RelationLinkManager arguments: ['@cache.cache'] + rest.link_manager.collection: + class: Drupal\rest\LinkManager\CollectionLinkManager diff --git a/core/modules/serialization/lib/Drupal/serialization/EntityCollection.php b/core/modules/serialization/lib/Drupal/serialization/EntityCollection.php index 7d2b7b9..e58eb66 100644 --- a/core/modules/serialization/lib/Drupal/serialization/EntityCollection.php +++ b/core/modules/serialization/lib/Drupal/serialization/EntityCollection.php @@ -12,6 +12,13 @@ class EntityCollection { /** + * An internal identifier for this collection (e.g. view name). + * + * @var string + */ + protected $id; + + /** * The entities in the collection. * * var array @@ -40,6 +47,16 @@ class EntityCollection { protected $description; /** + * Constructor. + * + * @param string $collection_id + * The internal identifier for the collection (e.g. view name). + */ + public function __construct($collection_id) { + $this->id = $collection_id; + } + + /** * Get the items list. * * @return array @@ -111,4 +128,4 @@ public function setDescription($description) { $this->description = $description; } -} \ No newline at end of file +}