TypeLinkManager::writeCache

protected TypeLinkManager::writeCache($context = array())

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.

File

core/modules/rest/src/LinkManager/TypeLinkManager.php, line 121

Class

TypeLinkManager

Namespace

Drupal\rest\LinkManager

Code

protected function writeCache($context = array()) {
  $data = array();

  // Type URIs correspond to bundles. Iterate through the bundles to get the
  // URI and data for them.
  $entity_types = \Drupal::entityManager()->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]->isSubclassOf('\Drupal\Core\Config\Entity\ConfigEntityInterface')) {
      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] = array(
        '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('rest:links:types', $data, Cache::PERMANENT, array('entity_types'));
  return $data;
}
doc_Drupal
2016-10-29 09:50:17
Comments
Leave a Comment

Please login to continue.