diff --git a/core/modules/rest/lib/Drupal/rest/LinkManager/RelationLinkManager.php b/core/modules/rest/lib/Drupal/rest/LinkManager/RelationLinkManager.php index 5836de1..2de3dfb 100644 --- a/core/modules/rest/lib/Drupal/rest/LinkManager/RelationLinkManager.php +++ b/core/modules/rest/lib/Drupal/rest/LinkManager/RelationLinkManager.php @@ -12,21 +12,6 @@ class RelationLinkManager implements RelationLinkManagerInterface{ /** - * @var \Drupal\Core\Cache\CacheBackendInterface; - */ - protected $cache; - - /** - * Constructor. - * - * @param \Drupal\Core\Cache\CacheBackendInterface $cache - * The cache of relation URIs and their associated Typed Data IDs. - */ - public function __construct(CacheBackendInterface $cache) { - $this->cache = $cache; - } - - /** * Get a relation link for the field. * * @param string $entity_type @@ -44,49 +29,4 @@ public function getRelationUri($entity_type, $bundle, $field_name) { return url("rest/relation/$entity_type/$bundle/$field_name", array('absolute' => TRUE)); } - /** - * Get the array of relation links. - * - * Any field can be handled as a relation simply by changing how it is - * normalized. Therefore, there is no prior knowledge that can be used here - * to determine which fields to assign relation URIs. Instead, each field, - * even primitives, are given a relation URI. It is up to the caller to - * determine which URIs to use. - * - * @return array - * An array of typed data ids (entity_type, bundle, and field name) keyed - * by corresponding relation URI. - */ - public function getRelations() { - $cid = 'rest:links:relations'; - $cache = $this->cache->get($cid); - if (!$cache) { - $this->writeCache(); - $cache = $this->cache->get($cid); - } - return $cache->data; - } - - /** - * Writes the cache of relation links. - */ - protected function writeCache() { - $data = array(); - - foreach (field_info_fields() as $field_info) { - foreach ($field_info['bundles'] as $entity_type => $bundles) { - foreach ($bundles as $bundle) { - $relation_uri = $this->getRelationUri($entity_type, $bundle, $field_info['field_name']); - $data[$relation_uri] = array( - 'entity_type' => $entity_type, - 'bundle' => $bundle, - 'field_name' => $field_info['field_name'], - ); - } - } - } - // These URIs only change when field info changes, so cache it permanently - // and only clear it when field_info is cleared. - $this->cache->set('rest:links:relations', $data, CacheBackendInterface::CACHE_PERMANENT, array('field_info' => TRUE)); - } } diff --git a/core/modules/rest/lib/Drupal/rest/LinkManager/TypeLinkManager.php b/core/modules/rest/lib/Drupal/rest/LinkManager/TypeLinkManager.php index bd43339..b1f075c 100644 --- a/core/modules/rest/lib/Drupal/rest/LinkManager/TypeLinkManager.php +++ b/core/modules/rest/lib/Drupal/rest/LinkManager/TypeLinkManager.php @@ -12,23 +12,6 @@ class TypeLinkManager implements TypeLinkManagerInterface { /** - * Injected cache backend. - * - * @var \Drupal\Core\Cache\CacheBackendInterface; - */ - protected $cache; - - /** - * Constructor. - * - * @param \Drupal\Core\Cache\CacheBackendInterface $cache - * The injected cache backend for caching type URIs. - */ - public function __construct(CacheBackendInterface $cache) { - $this->cache = $cache; - } - - /** * Get a type link for a bundle. * * @param string $entity_type @@ -44,51 +27,4 @@ public function getTypeUri($entity_type, $bundle) { return url("rest/type/$entity_type/$bundle", array('absolute' => TRUE)); } - /** - * Get the array of type links. - * - * @return array - * An array of typed data ids (entity_type and bundle) keyed by - * corresponding type URI. - */ - public function getTypes() { - $cid = 'rest:links:types'; - $cache = $this->cache->get($cid); - if (!$cache) { - $this->writeCache(); - $cache = $this->cache->get($cid); - } - return $cache->data; - } - - /** - * Writes the cache of type links. - */ - 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)); - } } diff --git a/core/modules/rest/lib/Drupal/rest/RestBundle.php b/core/modules/rest/lib/Drupal/rest/RestBundle.php index 294cbc6..37db78e 100644 --- a/core/modules/rest/lib/Drupal/rest/RestBundle.php +++ b/core/modules/rest/lib/Drupal/rest/RestBundle.php @@ -36,9 +36,7 @@ public function build(ContainerBuilder $container) { $container->register('rest.link_manager', 'Drupal\rest\LinkManager\LinkManager') ->addArgument(new Reference('rest.link_manager.type')) ->addArgument(new Reference('rest.link_manager.relation')); - $container->register('rest.link_manager.type', 'Drupal\rest\LinkManager\TypeLinkManager') - ->addArgument(new Reference('cache.cache')); - $container->register('rest.link_manager.relation', 'Drupal\rest\LinkManager\RelationLinkManager') - ->addArgument(new Reference('cache.cache')); + $container->register('rest.link_manager.type', 'Drupal\rest\LinkManager\TypeLinkManager'); + $container->register('rest.link_manager.relation', 'Drupal\rest\LinkManager\RelationLinkManager'); } }