Commit bfaf6b6e authored by effulgentsia's avatar effulgentsia

Issue #2758897 by Wim Leers, damiankloip, larowlan: Move rest module's "link...

Issue #2758897 by Wim Leers, damiankloip, larowlan: Move rest module's "link manager" services to serialization module
parent 414574e1
......@@ -5,5 +5,4 @@ package: Web services
version: VERSION
core: 8.x
dependencies:
- rest
- serialization
services:
serializer.normalizer.entity_reference_item.hal:
class: Drupal\hal\Normalizer\EntityReferenceItemNormalizer
arguments: ['@rest.link_manager', '@serializer.entity_resolver']
arguments: ['@serialization.link_manager', '@serializer.entity_resolver']
tags:
- { name: normalizer, priority: 10 }
serializer.normalizer.field_item.hal:
......@@ -16,10 +16,10 @@ services:
class: Drupal\hal\Normalizer\FileEntityNormalizer
tags:
- { name: normalizer, priority: 20 }
arguments: ['@entity.manager', '@http_client', '@rest.link_manager', '@module_handler']
arguments: ['@entity.manager', '@http_client', '@serialization.link_manager', '@module_handler']
serializer.normalizer.entity.hal:
class: Drupal\hal\Normalizer\ContentEntityNormalizer
arguments: ['@rest.link_manager', '@entity.manager', '@module_handler']
arguments: ['@serialization.link_manager', '@entity.manager', '@module_handler']
tags:
- { name: normalizer, priority: 10 }
serializer.encoder.hal:
......
......@@ -6,7 +6,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\rest\LinkManager\LinkManagerInterface;
use Drupal\serialization\LinkManager\LinkManagerInterface;
use Drupal\serialization\Normalizer\FieldableEntityNormalizerTrait;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
......@@ -27,7 +27,7 @@ class ContentEntityNormalizer extends NormalizerBase {
/**
* The hypermedia link manager.
*
* @var \Drupal\rest\LinkManager\LinkManagerInterface
* @var \Drupal\serialization\LinkManager\LinkManagerInterface
*/
protected $linkManager;
......@@ -41,7 +41,7 @@ class ContentEntityNormalizer extends NormalizerBase {
/**
* Constructs an ContentEntityNormalizer object.
*
* @param \Drupal\rest\LinkManager\LinkManagerInterface $link_manager
* @param \Drupal\serialization\LinkManager\LinkManagerInterface $link_manager
* The hypermedia link manager.
*/
public function __construct(LinkManagerInterface $link_manager, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler) {
......
......@@ -3,7 +3,7 @@
namespace Drupal\hal\Normalizer;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\rest\LinkManager\LinkManagerInterface;
use Drupal\serialization\LinkManager\LinkManagerInterface;
use Drupal\serialization\EntityResolver\EntityResolverInterface;
use Drupal\serialization\EntityResolver\UuidReferenceInterface;
......@@ -22,7 +22,7 @@ class EntityReferenceItemNormalizer extends FieldItemNormalizer implements UuidR
/**
* The hypermedia link manager.
*
* @var \Drupal\rest\LinkManager\LinkManagerInterface
* @var \Drupal\serialization\LinkManager\LinkManagerInterface
*/
protected $linkManager;
......@@ -36,7 +36,7 @@ class EntityReferenceItemNormalizer extends FieldItemNormalizer implements UuidR
/**
* Constructs an EntityReferenceItemNormalizer object.
*
* @param \Drupal\rest\LinkManager\LinkManagerInterface $link_manager
* @param \Drupal\serialization\LinkManager\LinkManagerInterface $link_manager
* The hypermedia link manager.
* @param \Drupal\serialization\EntityResolver\EntityResolverInterface $entity_Resolver
* The entity resolver.
......
......@@ -4,7 +4,7 @@
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\rest\LinkManager\LinkManagerInterface;
use Drupal\serialization\LinkManager\LinkManagerInterface;
use GuzzleHttp\ClientInterface;
/**
......@@ -33,7 +33,7 @@ class FileEntityNormalizer extends ContentEntityNormalizer {
* The entity manager.
* @param \GuzzleHttp\ClientInterface $http_client
* The HTTP Client.
* @param \Drupal\rest\LinkManager\LinkManagerInterface $link_manager
* @param \Drupal\serialization\LinkManager\LinkManagerInterface $link_manager
* The hypermedia link manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
......
......@@ -7,9 +7,9 @@
use Drupal\hal\Encoder\JsonEncoder;
use Drupal\hal\Normalizer\FieldItemNormalizer;
use Drupal\hal\Normalizer\FileEntityNormalizer;
use Drupal\rest\LinkManager\LinkManager;
use Drupal\rest\LinkManager\RelationLinkManager;
use Drupal\rest\LinkManager\TypeLinkManager;
use Drupal\serialization\LinkManager\LinkManager;
use Drupal\serialization\LinkManager\RelationLinkManager;
use Drupal\serialization\LinkManager\TypeLinkManager;
use Symfony\Component\Serializer\Serializer;
......
......@@ -10,9 +10,9 @@
use Drupal\hal\Normalizer\FieldItemNormalizer;
use Drupal\hal\Normalizer\FieldNormalizer;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\rest\LinkManager\LinkManager;
use Drupal\rest\LinkManager\RelationLinkManager;
use Drupal\rest\LinkManager\TypeLinkManager;
use Drupal\serialization\LinkManager\LinkManager;
use Drupal\serialization\LinkManager\RelationLinkManager;
use Drupal\serialization\LinkManager\TypeLinkManager;
use Drupal\serialization\EntityResolver\ChainEntityResolver;
use Drupal\serialization\EntityResolver\TargetIdResolver;
use Drupal\serialization\EntityResolver\UuidResolver;
......@@ -30,7 +30,7 @@ abstract class NormalizerTestBase extends KernelTestBase {
*
* @var array
*/
public static $modules = ['entity_test', 'field', 'hal', 'language', 'rest', 'serialization', 'system', 'text', 'user', 'filter'];
public static $modules = ['entity_test', 'field', 'hal', 'language', 'serialization', 'system', 'text', 'user', 'filter'];
/**
* The mock serializer.
......
# Set the domain for REST type and relation links.
# If left blank, the site's domain will be used.
link_domain: ~
# Before Drupal 8.2, EntityResource used permissions as well as the entity
# access system for access checking. This was confusing, and it only did this
# for historical reasons. New Drupal installations opt out from this by default
......
......@@ -3,6 +3,7 @@ rest.settings:
type: config_object
label: 'REST settings'
mapping:
# @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0.
link_domain:
type: string
label: 'Domain of the relation'
......
......@@ -31,6 +31,9 @@ function hook_rest_resource_alter(&$definitions) {
/**
* Alter the REST type URI.
*
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. Use
* hook_serialization_type_uri_alter() instead. This exists solely for BC.
*
* Modules may wish to alter the type URI generated for a resource based on the
* context of the serializer/normalizer operation.
*
......@@ -46,7 +49,7 @@ function hook_rest_resource_alter(&$definitions) {
*/
function hook_rest_type_uri_alter(&$uri, $context = array()) {
if ($context['mymodule'] == TRUE) {
$base = \Drupal::config('rest.settings')->get('link_domain');
$base = \Drupal::config('serialization.settings')->get('link_domain');
$uri = str_replace($base, 'http://mymodule.domain', $uri);
}
}
......@@ -55,6 +58,9 @@ function hook_rest_type_uri_alter(&$uri, $context = array()) {
/**
* Alter the REST relation URI.
*
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. Use
* hook_serialization_relation_uri_alter() instead. This exists solely for BC.
*
* Modules may wish to alter the relation URI generated for a resource based on
* the context of the serializer/normalizer operation.
*
......@@ -70,7 +76,7 @@ function hook_rest_type_uri_alter(&$uri, $context = array()) {
*/
function hook_rest_relation_uri_alter(&$uri, $context = array()) {
if ($context['mymodule'] == TRUE) {
$base = \Drupal::config('rest.settings')->get('link_domain');
$base = \Drupal::config('serialization.settings')->get('link_domain');
$uri = str_replace($base, 'http://mymodule.domain', $uri);
}
}
......
......@@ -11,15 +11,22 @@ services:
# @todo Remove this service in Drupal 9.0.0.
access_check.rest.csrf:
alias: access_check.header.csrf
# Link managers.
# @deprecated in Drupal 8.3.x and will be removed before 9.0.0. Use
# serialization.link_manager instead.
rest.link_manager:
parent: serialization.link_manager
class: Drupal\rest\LinkManager\LinkManager
arguments: ['@rest.link_manager.type', '@rest.link_manager.relation']
# @deprecated in Drupal 8.3.x and will be removed before 9.0.0. Use
# serialization.link_manager.type instead.
rest.link_manager.type:
parent: serialization.link_manager.type
class: Drupal\rest\LinkManager\TypeLinkManager
arguments: ['@cache.default', '@module_handler', '@config.factory', '@request_stack', '@entity_type.bundle.info']
# @deprecated in Drupal 8.3.x and will be removed before 9.0.0. Use
# serialization.link_manager.relation instead.
rest.link_manager.relation:
parent: serialization.link_manager.relation
class: Drupal\rest\LinkManager\RelationLinkManager
arguments: ['@cache.default', '@entity.manager', '@module_handler', '@config.factory', '@request_stack']
rest.resource_routes:
class: Drupal\rest\Routing\ResourceRoutes
arguments: ['@plugin.manager.rest', '@entity_type.manager', '@logger.channel.rest']
......
......@@ -2,19 +2,10 @@
namespace Drupal\rest\LinkManager;
use Drupal\serialization\LinkManager\ConfigurableLinkManagerInterface as MovedConfigurableLinkManagerInterface;
/**
* Defines an interface for a link manager with a configurable domain.
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. This has
* been moved to the serialization module. This exists solely for BC.
*/
interface ConfigurableLinkManagerInterface {
/**
* Sets the link domain used in constructing link URIs.
*
* @param string $domain
* The link domain to use for constructing link URIs.
*
* @return $this
*/
public function setLinkDomain($domain);
}
interface ConfigurableLinkManagerInterface extends MovedConfigurableLinkManagerInterface {}
......@@ -2,70 +2,10 @@
namespace Drupal\rest\LinkManager;
class LinkManager implements LinkManagerInterface {
use Drupal\serialization\LinkManager\LinkManager as MovedLinkManager;
/**
* The type link manager.
*
* @var \Drupal\rest\LinkManager\TypeLinkManagerInterface
*/
protected $typeLinkManager;
/**
* The relation link manager.
*
* @var \Drupal\rest\LinkManager\RelationLinkManagerInterface
*/
protected $relationLinkManager;
/**
* Constructor.
*
* @param \Drupal\rest\LinkManager\TypeLinkManagerInterface $type_link_manager
* Manager for handling bundle URIs.
* @param \Drupal\rest\LinkManager\RelationLinkManagerInterface $relation_link_manager
* Manager for handling bundle URIs.
*/
public function __construct(TypeLinkManagerInterface $type_link_manager, RelationLinkManagerInterface $relation_link_manager) {
$this->typeLinkManager = $type_link_manager;
$this->relationLinkManager = $relation_link_manager;
}
/**
* {@inheritdoc}
*/
public function getTypeUri($entity_type, $bundle, $context = array()) {
return $this->typeLinkManager->getTypeUri($entity_type, $bundle, $context);
}
/**
* {@inheritdoc}
*/
public function getTypeInternalIds($type_uri, $context = array()) {
return $this->typeLinkManager->getTypeInternalIds($type_uri, $context);
}
/**
* {@inheritdoc}
*/
public function getRelationUri($entity_type, $bundle, $field_name, $context = array()) {
return $this->relationLinkManager->getRelationUri($entity_type, $bundle, $field_name, $context);
}
/**
* {@inheritdoc}
*/
public function getRelationInternalIds($relation_uri) {
return $this->relationLinkManager->getRelationInternalIds($relation_uri);
}
/**
* {@inheritdoc}
*/
public function setLinkDomain($domain) {
$this->relationLinkManager->setLinkDomain($domain);
$this->typeLinkManager->setLinkDomain($domain);
return $this;
}
}
/**
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. This has
* been moved to the serialization module. This exists solely for BC.
*/
class LinkManager extends MovedLinkManager implements LinkManagerInterface {}
......@@ -2,57 +2,10 @@
namespace Drupal\rest\LinkManager;
use Drupal\serialization\LinkManager\LinkManagerBase as MovedLinkManagerBase;
/**
* Defines an abstract base-class for REST link manager objects.
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. This has
* been moved to the serialization module. This exists solely for BC.
*/
abstract class LinkManagerBase {
/**
* Link domain used for type links URIs.
*
* @var string
*/
protected $linkDomain;
/**
* Config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* {@inheritdoc}
*/
public function setLinkDomain($domain) {
$this->linkDomain = rtrim($domain, '/');
return $this;
}
/**
* Gets the link domain.
*
* @return string
* The link domain.
*/
protected function getLinkDomain() {
if (empty($this->linkDomain)) {
if ($domain = $this->configFactory->get('rest.settings')->get('link_domain')) {
$this->linkDomain = rtrim($domain, '/');
}
else {
$request = $this->requestStack->getCurrentRequest();
$this->linkDomain = $request->getSchemeAndHttpHost() . $request->getBasePath();
}
}
return $this->linkDomain;
}
}
abstract class LinkManagerBase extends MovedLinkManagerBase {}
......@@ -2,17 +2,10 @@
namespace Drupal\rest\LinkManager;
use Drupal\serialization\LinkManager\LinkManagerInterface as MovedLinkManagerInterface;
/**
* Interface implemented by link managers.
*
* There are no explicit methods on the manager interface. Instead link managers
* broker the interactions of the different components, and therefore must
* implement each component interface, which is enforced by this interface
* extending all of the component ones.
*
* While a link manager may directly implement these interface methods with
* custom logic, it is expected to be more common for plugin managers to proxy
* the method invocations to the respective components.
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. This has
* been moved to the serialization module. This exists solely for BC.
*/
interface LinkManagerInterface extends TypeLinkManagerInterface, RelationLinkManagerInterface {
}
interface LinkManagerInterface extends MovedLinkManagerInterface {}
......@@ -2,141 +2,10 @@
namespace Drupal\rest\LinkManager;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\serialization\LinkManager\RelationLinkManager as MovedLinkRelationManager;
class RelationLinkManager extends LinkManagerBase implements RelationLinkManagerInterface {
/**
* @var \Drupal\Core\Cache\CacheBackendInterface;
*/
protected $cache;
/**
* Entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructor.
*
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* The cache of relation URIs and their associated Typed Data IDs.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
*/
public function __construct(CacheBackendInterface $cache, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory, RequestStack $request_stack) {
$this->cache = $cache;
$this->entityManager = $entity_manager;
$this->configFactory = $config_factory;
$this->moduleHandler = $module_handler;
$this->requestStack = $request_stack;
}
/**
* {@inheritdoc}
*/
public function getRelationUri($entity_type, $bundle, $field_name, $context = array()) {
// Per the interface documention of this method, the returned URI may
// optionally also serve as the URL of a documentation page about this
// field. However, the REST module does not currently implement such
// a documentation page. Therefore, we return a URI assembled relative to
// the site's base URL, which is sufficient to uniquely identify the site's
// entity type + bundle + field for use in hypermedia formats, but we do
// not take into account unclean URLs, language prefixing, or anything else
// that would be required for Drupal to be able to respond with content
// at this URL. If a module is installed that adds such content, but
// requires this URL to be different (e.g., include a language prefix),
// then the module must also override the RelationLinkManager class/service
// to return the desired URL.
$uri = $this->getLinkDomain() . "/rest/relation/$entity_type/$bundle/$field_name";
$this->moduleHandler->alter('rest_relation_uri', $uri, $context);
return $uri;
}
/**
* {@inheritdoc}
*/
public function getRelationInternalIds($relation_uri, $context = array()) {
$relations = $this->getRelations($context);
if (isset($relations[$relation_uri])) {
return $relations[$relation_uri];
}
return FALSE;
}
/**
* 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.
*
* @param array $context
* Context from the normalizer/serializer operation.
*
* @return array
* An array of typed data ids (entity_type, bundle, and field name) keyed
* by corresponding relation URI.
*/
protected function getRelations($context = array()) {
$cid = 'rest:links:relations';
$cache = $this->cache->get($cid);
if (!$cache) {
$this->writeCache($context);
$cache = $this->cache->get($cid);
}
return $cache->data;
}
/**
* 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'));
}
}
/**
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. This has
* been moved to the serialization module. This exists solely for BC.
*/
class RelationLinkManager extends MovedLinkRelationManager implements RelationLinkManagerInterface {}
......@@ -2,38 +2,10 @@
namespace Drupal\rest\LinkManager;
interface RelationLinkManagerInterface extends ConfigurableLinkManagerInterface {
use Drupal\serialization\LinkManager\RelationLinkManagerInterface as MovedRelationLinkManagerInterface;
/**
* Gets the URI that corresponds to a field.
*
* When using hypermedia formats, this URI can be used to indicate which
* field the data represents. Documentation about this field can also be
* provided at this URI.
*
* @param string $entity_type
* The bundle's entity type.
* @param string $bundle
* The bundle name.
* @param string $field_name
* The field name.
* @param array $context
* (optional) Optional serializer/normalizer context.
*
* @return string
* The corresponding URI for the field.
*/
public function getRelationUri($entity_type, $bundle, $field_name, $context = array());
/**
* Translates a REST URI into internal IDs.
*
* @param string $relation_uri
* Relation URI to transform into internal IDs
*
* @return array
* Array with keys 'entity_type', 'bundle' and 'field_name'.
*/
public function getRelationInternalIds($relation_uri);
}
/**
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. This has
* been moved to the serialization module. This exists solely for BC.
*/
interface RelationLinkManagerInterface extends MovedRelationLinkManagerInterface {}
......@@ -2,148 +2,10 @@
namespace Drupal\rest\LinkManager;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\serialization\LinkManager\TypeLinkManager as MovedTypeLinkManager;
class TypeLinkManager extends LinkManagerBase implements TypeLinkManagerInterface {
/**
* Injected cache backend.
*
* @var \Drupal\Core\Cache\CacheBackendInterface;
*/
protected $cache;
/**
* Module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The bundle info service.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $bundleInfoService;
/**
* Constructor.
*
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* The injected cache backend for caching type URIs.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundle_info_service
* The bundle info service.
*/
public function __construct(CacheBackendInterface $cache, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory, RequestStack $request_stack, EntityTypeBundleInfoInterface $bundle_info_service) {
$this->cache = $cache;
$this->configFactory = $config_factory;
$this->moduleHandler = $module_handler;
$this->requestStack = $request_stack;
$this->bundleInfoService = $bundle_info_service;
}
/**
* {@inheritdoc}
*/
public function getTypeUri($entity_type, $bundle, $context = array()) {
// Per the interface documention of this method, the returned URI may
// optionally also serve as the URL of a documentation page about this
// bundle. However, the REST module does not currently implement such
// a documentation page. Therefore, we return a URI assembled relative to
// the site's base URL, which is sufficient to uniquely identify the site's
// entity type and bundle for use in hypermedia formats, but we do not
// take into account unclean URLs, language prefixing, or anything else
// that would be required for Drupal to be able to respond with content
// at this URL. If a module is installed that adds such content, but
// requires this URL to be different (e.g., include a language prefix),
// then the module must also override the TypeLinkManager class/service to
// return the desired URL.
$uri = $this->getLinkDomain() . "/rest/type/$entity_type/$bundle";
$this->moduleHandler->alter('rest_type_uri', $uri, $context);
return $uri;
}
/**
* {@inheritdoc}
*/
public function getTypeInternalIds($type_uri, $context = array()) {
$types = $this->getTypes($context);
if (isset($types[$type_uri])) {
return $types[$type_uri];
}
return FALSE;
}
/**
* Get the array of type links.
*
* @param array $context
* Context from the normalizer/serializer operation.
*
* @return array
* An array of typed data ids (entity_type and bundle) keyed by
* corresponding type URI.
*/
protected function getTypes($context = array()) {
$cid = 'rest:links:types';
$cache = $this->cache->get($cid);
if (!$cache) {
$data = $this->writeCache($context);
}
else {
$data = $cache->data;
}
return $data;