function RelationLinkManager::writeCache

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

Writes the cache of relation links.

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'

The values for 'entity_type_id', 'bundle' and 'field_name' are strings.

1 call to RelationLinkManager::writeCache()
RelationLinkManager::getRelations in core/modules/hal/src/LinkManager/RelationLinkManager.php
Get the array of relation links.

File

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

Class

RelationLinkManager

Namespace

Drupal\hal\LinkManager

Code

protected function writeCache($context = []) {
    $data = [];
    foreach ($this->entityTypeManager
        ->getDefinitions() as $entity_type) {
        if ($entity_type instanceof ContentEntityTypeInterface) {
            foreach ($this->entityTypeBundleInfo
                ->getBundleInfo($entity_type->id()) as $bundle => $bundle_info) {
                foreach ($this->entityFieldManager
                    ->getFieldDefinitions($entity_type->id(), $bundle) as $field_definition) {
                    $relation_uri = $this->getRelationUri($entity_type->id(), $bundle, $field_definition->getName(), $context);
                    $data[$relation_uri] = [
                        'entity_type_id' => $entity_type->id(),
                        'bundle' => $bundle,
                        'field_name' => $field_definition->getName(),
                    ];
                }
            }
        }
    }
    // These URIs only change when field info changes, so cache it permanently
    // and only clear it when the fields cache is cleared.
    $this->cache
        ->set('hal:links:relations:' . $this->getLinkDomain($context), $data, Cache::PERMANENT, [
        'entity_field_info',
    ]);
    return $data;
}

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