protected function TypeLinkManager::writeCache

Writes the cache of type links.

1 call to TypeLinkManager::writeCache()
TypeLinkManager::getTypes in drupal/core/modules/rest/lib/Drupal/rest/LinkManager/TypeLinkManager.php
Get the array of type links.

File

drupal/core/modules/rest/lib/Drupal/rest/LinkManager/TypeLinkManager.php, line 78
Contains \Drupal\rest\LinkManager\TypeLinkManager.

Class

TypeLinkManager

Namespace

Drupal\rest\LinkManager

Code

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

  // Type URIs correspond to bundles. Iterate through the bundles to get the
  // URI and data for them.
  $entity_info = entity_get_info();
  foreach (entity_get_bundles() as $entity_type => $bundles) {
    $entity_type_info = $entity_info[$entity_type];
    $reflection = new \ReflectionClass($entity_type_info['class']);

    // Only content entities are supported currently.
    // @todo Consider supporting config entities.
    if ($reflection
      ->implementsInterface('\\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, $bundle);
      $data[$bundle_uri] = array(
        'entity_type' => $entity_type,
        '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, CacheBackendInterface::CACHE_PERMANENT, array(
    'entity_info' => TRUE,
  ));
}