function TypeLinkManager::writeCache

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

Writes the cache of type links.

Parameters

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

Return value

array An array of typed data ids (entity_type and bundle) keyed by corresponding type URI.

1 call to TypeLinkManager::writeCache()
TypeLinkManager::getTypes in core/modules/hal/src/LinkManager/TypeLinkManager.php
Get the array of type links.

File

core/modules/hal/src/LinkManager/TypeLinkManager.php, line 132

Class

TypeLinkManager

Namespace

Drupal\hal\LinkManager

Code

protected function writeCache($context = []) {
    $data = [];
    // Type URIs correspond to bundles. Iterate through the bundles to get the
    // URI and data for them.
    $entity_types = $this->entityTypeManager
        ->getDefinitions();
    foreach ($this->bundleInfoService
        ->getAllBundleInfo() as $entity_type_id => $bundles) {
        // Only content entities are supported currently.
        // @todo Consider supporting config entities.
        if ($entity_types[$entity_type_id]->entityClassImplements(ConfigEntityInterface::class)) {
            continue;
        }
        foreach ($bundles as $bundle => $bundle_info) {
            // Get a type URI for the bundle.
            $bundle_uri = $this->getTypeUri($entity_type_id, $bundle, $context);
            $data[$bundle_uri] = [
                'entity_type' => $entity_type_id,
                'bundle' => $bundle,
            ];
        }
    }
    // These URIs only change when entity info changes, so cache it permanently
    // and only clear it when entity_info is cleared.
    $this->cache
        ->set('hal:links:types:' . $this->getLinkDomain($context), $data, Cache::PERMANENT, [
        'entity_types',
    ]);
    return $data;
}

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