Esempio n. 1
0
 /**
  * Writes the cache of relation links.
  *
  * @param array $context
  *   Context from the normalizer/serializer operation.
  */
 protected function writeCache($context = array())
 {
     $data = array();
     foreach ($this->entityManager->getDefinitions() as $entity_type) {
         if ($entity_type instanceof ContentEntityTypeInterface) {
             foreach ($this->entityManager->getBundleInfo($entity_type->id()) as $bundle => $bundle_info) {
                 foreach ($this->entityManager->getFieldDefinitions($entity_type->id(), $bundle) as $field_definition) {
                     $relation_uri = $this->getRelationUri($entity_type->id(), $bundle, $field_definition->getName(), $context);
                     $data[$relation_uri] = array('entity_type' => $entity_type, '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('rest:links:relations', $data, Cache::PERMANENT, array('entity_field_info'));
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  *
  * Cache an array of the paths available on each page. We assume that aliases
  * will be needed for the majority of these paths during subsequent requests,
  * and load them in a single query during path alias lookup.
  */
 public function writeCache()
 {
     // Check if the paths for this page were loaded from cache in this request
     // to avoid writing to cache on every request.
     if ($this->cacheNeedsWriting && !empty($this->cacheKey)) {
         // Start with the preloaded path lookups, so that cached entries for other
         // languages will not be lost.
         $path_lookups = $this->preloadedPathLookups ?: array();
         foreach ($this->lookupMap as $langcode => $lookups) {
             $path_lookups[$langcode] = array_keys($lookups);
             if (!empty($this->noAlias[$langcode])) {
                 $path_lookups[$langcode] = array_merge($path_lookups[$langcode], array_keys($this->noAlias[$langcode]));
             }
         }
         $twenty_four_hours = 60 * 60 * 24;
         $this->cache->set($this->cacheKey, $path_lookups, $this->getRequestTime() + $twenty_four_hours);
     }
 }
Esempio n. 3
0
 /**
  * Writes the cache of type links.
  *
  * @param array $context
  *   Context from the normalizer/serializer operation.
  */
 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 (entity_get_bundles() 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'));
 }