function RelationLinkManager::getRelations

Same name in other branches
  1. 9 core/modules/hal/src/LinkManager/RelationLinkManager.php \Drupal\hal\LinkManager\RelationLinkManager::getRelations()

Get the array of relation links.

Any field can be handled as a relation simply by changing how it is normalized. Therefore, there is no prior knowledge that can be used here to determine which fields to assign relation URIs. Instead, each field, even primitives, are given a relation URI. It is up to the caller to determine which URIs to use.

Parameters

array $context: Context from the normalizer/serializer operation.

Return value

array An array of typed data IDs keyed by corresponding relation URI. The keys are:

  • 'entity_type_id'
  • 'bundle'
  • 'field_name'
  • 'entity_type' (deprecated)

The values for 'entity_type_id', 'bundle' and 'field_name' are strings. The 'entity_type' key exists for backwards compatibility and its value is the full entity type object. The 'entity_type' key will be removed before Drupal 9.0.

See also

https://www.drupal.org/node/2877608

1 call to RelationLinkManager::getRelations()
RelationLinkManager::getRelationInternalIds in core/modules/hal/src/LinkManager/RelationLinkManager.php
Translates a REST URI into internal IDs.

File

core/modules/hal/src/LinkManager/RelationLinkManager.php, line 151

Class

RelationLinkManager

Namespace

Drupal\hal\LinkManager

Code

protected function getRelations($context = []) {
    $cid = 'hal:links:relations';
    $cache = $this->cache
        ->get($cid);
    if (!$cache) {
        $data = $this->writeCache($context);
    }
    else {
        $data = $cache->data;
    }
    // @todo https://www.drupal.org/node/2716163 Remove this in Drupal 9.0.
    foreach ($data as $relation_uri => $ids) {
        $data[$relation_uri]['entity_type'] = $this->entityTypeManager
            ->getDefinition($ids['entity_type_id']);
    }
    return $data;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.