src/Configuration/ResourceConfig.php | 52 +++++++++++++++------- src/Configuration/ResourceConfigInterface.php | 51 --------------------- src/Configuration/ResourceManager.php | 25 +++++++---- src/Configuration/ResourceManagerInterface.php | 34 -------------- src/Context/CurrentContext.php | 10 ++--- src/Context/CurrentContextInterface.php | 4 +- src/LinkManager/LinkManager.php | 4 +- src/LinkManager/LinkManagerInterface.php | 6 +-- src/Normalizer/EntityNormalizer.php | 12 ++--- src/Normalizer/EntityReferenceFieldNormalizer.php | 9 ++-- src/Normalizer/NormalizerBase.php | 2 +- src/Normalizer/Relationship.php | 8 ++-- src/Normalizer/RelationshipItem.php | 8 ++-- src/Normalizer/RelationshipItemNormalizer.php | 8 ++-- src/Normalizer/RelationshipNormalizer.php | 8 ++-- .../Value/RelationshipNormalizerValue.php | 2 +- src/RequestHandler.php | 2 +- src/Resource/EntityResource.php | 10 ++--- src/Routing/Routes.php | 16 +++---- .../Kernel/Configuration/ResourceManagerTest.php | 13 +++--- tests/src/Unit/Context/CurrentContextTest.php | 6 +-- .../Unit/Normalizer/ConfigEntityNormalizerTest.php | 4 +- .../EntityReferenceFieldNormalizerTest.php | 4 +- .../JsonApiDocumentTopLevelNormalizerTest.php | 6 +-- tests/src/Unit/Routing/RoutesTest.php | 4 +- 25 files changed, 125 insertions(+), 183 deletions(-) diff --git a/src/Configuration/ResourceConfig.php b/src/Configuration/ResourceConfig.php index 8a02d8b..5caf054 100644 --- a/src/Configuration/ResourceConfig.php +++ b/src/Configuration/ResourceConfig.php @@ -13,7 +13,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; * * @internal */ -class ResourceConfig implements ResourceConfigInterface { +class ResourceConfig { /** * The entity type ID. @@ -27,7 +27,7 @@ class ResourceConfig implements ResourceConfigInterface { * * @var string */ - protected $bundleId; + protected $bundle; /** * The type name. @@ -51,35 +51,55 @@ class ResourceConfig implements ResourceConfigInterface { protected $deserializationTargetClass; /** - * {@inheritdoc} + * Gets the entity type ID. + * + * @return string + * The entity type ID. + * + * @see \Drupal\Core\Entity\EntityInterface::getEntityTypeId */ public function getEntityTypeId() { return $this->entityTypeId; } /** - * {@inheritdoc} + * Gets the bundle. + * + * @return string + * The bundle of the entity. Defaults to the entity type ID if the entity + * type does not make use of different bundles. + * + * @see \Drupal\Core\Entity\EntityInterface::bundle */ - public function getTypeName() { - return $this->typeName; + public function getBundle() { + return $this->bundle; } /** - * {@inheritdoc} + * Gets the type name. + * + * @return string + * The type name. */ - public function getPath() { - return $this->path; + public function getTypeName() { + return $this->typeName; } /** - * {@inheritdoc} + * Gets the path. + * + * @return string + * The path. */ - public function getBundleId() { - return $this->bundleId; + public function getPath() { + return $this->path; } /** - * {@inheritdoc} + * Gets the deserialization target class. + * + * @return string + * The deserialization target class. */ public function getDeserializationTargetClass() { return $this->deserializationTargetClass; @@ -97,11 +117,11 @@ class ResourceConfig implements ResourceConfigInterface { */ public function __construct($entity_type_id, $bundle_id, $deserialization_target_class) { $this->entityTypeId = $entity_type_id; - $this->bundleId = $bundle_id; + $this->bundle = $bundle_id; $this->deserializationTargetClass = $deserialization_target_class; - $this->typeName = sprintf('%s--%s', $this->entityTypeId, $this->bundleId); - $this->path= sprintf('/%s/%s', $this->entityTypeId, $this->bundleId); + $this->typeName = sprintf('%s--%s', $this->entityTypeId, $this->bundle); + $this->path= sprintf('/%s/%s', $this->entityTypeId, $this->bundle); } } diff --git a/src/Configuration/ResourceConfigInterface.php b/src/Configuration/ResourceConfigInterface.php deleted file mode 100644 index e2d816d..0000000 --- a/src/Configuration/ResourceConfigInterface.php +++ /dev/null @@ -1,51 +0,0 @@ -all) { @@ -71,14 +72,22 @@ class ResourceManager implements ResourceManagerInterface { } /** - * {@inheritdoc} + * Finds a resource config. + * + * @param string $entity_type_id + * The entity type id. + * @param string $bundle_id + * The id for the bundle to find. + * + * @return ResourceConfig + * The resource config found. NULL if none was found. */ public function get($entity_type_id, $bundle_id) { if (empty($entity_type_id)) { throw new PreconditionFailedHttpException('Server error. The current route is malformed.'); } foreach ($this->all(TRUE) as $resource) { - if ($resource->getEntityTypeId() == $entity_type_id && $resource->getBundleId() == $bundle_id) { + if ($resource->getEntityTypeId() == $entity_type_id && $resource->getBundle() == $bundle_id) { return $resource; } } diff --git a/src/Configuration/ResourceManagerInterface.php b/src/Configuration/ResourceManagerInterface.php deleted file mode 100644 index 2d8e741..0000000 --- a/src/Configuration/ResourceManagerInterface.php +++ /dev/null @@ -1,34 +0,0 @@ -resourceManager = $resource_manager; $this->requestStack = $request_stack; $this->routeMatch = $route_match; diff --git a/src/Context/CurrentContextInterface.php b/src/Context/CurrentContextInterface.php index 1dd2ab6..68357a9 100644 --- a/src/Context/CurrentContextInterface.php +++ b/src/Context/CurrentContextInterface.php @@ -16,7 +16,7 @@ interface CurrentContextInterface { /** * Returns a ResouceConfig for the current request. * - * @return \Drupal\jsonapi\Configuration\ResourceConfigInterface + * @return \Drupal\jsonapi\Configuration\ResourceConfig * The ResourceConfig object corresponding to the current request. */ public function getResourceConfig(); @@ -32,7 +32,7 @@ interface CurrentContextInterface { /** * Returns the resource manager. * - * @return \Drupal\jsonapi\Configuration\ResourceManagerInterface + * @return \Drupal\jsonapi\Configuration\ResourceManager */ public function getResourceManager(); diff --git a/src/LinkManager/LinkManager.php b/src/LinkManager/LinkManager.php index 1b18e6e..509f653 100644 --- a/src/LinkManager/LinkManager.php +++ b/src/LinkManager/LinkManager.php @@ -3,7 +3,7 @@ namespace Drupal\jsonapi\LinkManager; use Drupal\Core\Routing\UrlGeneratorInterface; -use Drupal\jsonapi\Configuration\ResourceConfigInterface; +use Drupal\jsonapi\Configuration\ResourceConfig; use Drupal\jsonapi\Error\SerializableHttpException; use Drupal\jsonapi\Routing\Param\OffsetPage; use Symfony\Cmf\Component\Routing\RouteObjectInterface; @@ -43,7 +43,7 @@ class LinkManager implements LinkManagerInterface { /** * {@inheritdoc} */ - public function getEntityLink($entity_id, ResourceConfigInterface $resource_config, array $route_parameters, $key) { + public function getEntityLink($entity_id, ResourceConfig $resource_config, array $route_parameters, $key) { $route_parameters += [ $resource_config->getEntityTypeId() => $entity_id, '_format' => 'api_json', diff --git a/src/LinkManager/LinkManagerInterface.php b/src/LinkManager/LinkManagerInterface.php index ec43d84..72829ab 100644 --- a/src/LinkManager/LinkManagerInterface.php +++ b/src/LinkManager/LinkManagerInterface.php @@ -3,7 +3,7 @@ namespace Drupal\jsonapi\LinkManager; -use Drupal\jsonapi\Configuration\ResourceConfigInterface; +use Drupal\jsonapi\Configuration\ResourceConfig; use Symfony\Component\HttpFoundation\Request; /** @@ -19,7 +19,7 @@ interface LinkManagerInterface { * @param int $entity_id * The entity ID to generate the link for. Note: Depending on the * configuration this might be the UUID as well. - * @param \Drupal\jsonapi\Configuration\ResourceConfigInterface $resource_config + * @param \Drupal\jsonapi\Configuration\ResourceConfig $resource_config * The resource configuration. * @param array $route_parameters * Parameters for the route generation. @@ -29,7 +29,7 @@ interface LinkManagerInterface { * @return string * The URL string. */ - public function getEntityLink($entity_id, ResourceConfigInterface $resource_config, array $route_parameters, $key); + public function getEntityLink($entity_id, ResourceConfig $resource_config, array $route_parameters, $key); /** * Get the full URL for a given request object. diff --git a/src/Normalizer/EntityNormalizer.php b/src/Normalizer/EntityNormalizer.php index af7225b..c9ebc6a 100644 --- a/src/Normalizer/EntityNormalizer.php +++ b/src/Normalizer/EntityNormalizer.php @@ -7,7 +7,7 @@ use Drupal\Core\Cache\RefinableCacheableDependencyInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\EntityReferenceFieldItemList; -use Drupal\jsonapi\Configuration\ResourceConfigInterface; +use Drupal\jsonapi\Configuration\ResourceConfig; use Drupal\jsonapi\Context\CurrentContextInterface; use Drupal\jsonapi\Error\SerializableHttpException; use Drupal\jsonapi\LinkManager\LinkManagerInterface; @@ -43,7 +43,7 @@ class EntityNormalizer extends NormalizerBase implements DenormalizerInterface, /** * The resource manager. * - * @var \Drupal\jsonapi\Configuration\ResourceManagerInterface + * @var \Drupal\jsonapi\Configuration\ResourceManager */ protected $resourceManager; @@ -90,7 +90,7 @@ class EntityNormalizer extends NormalizerBase implements DenormalizerInterface, $resource_type = $context['resource_config']->getTypeName(); // Get the bundle ID of the requested resource. This is used to determine if // this is a bundle level resource or an entity level resource. - $bundle_id = $context['resource_config']->getBundleId(); + $bundle_id = $context['resource_config']->getBundle(); if (!empty($context['sparse_fieldset'][$resource_type])) { $field_names = $context['sparse_fieldset'][$resource_type]; } @@ -137,13 +137,13 @@ class EntityNormalizer extends NormalizerBase implements DenormalizerInterface, * {@inheritdoc} */ public function denormalize($data, $class, $format = NULL, array $context = array()) { - if (empty($context['resource_config']) || !$context['resource_config'] instanceof ResourceConfigInterface) { + if (empty($context['resource_config']) || !$context['resource_config'] instanceof ResourceConfig) { throw new SerializableHttpException(412, 'Missing context during denormalization.'); } - /* @var \Drupal\jsonapi\Configuration\ResourceConfigInterface $resource_config */ + /* @var \Drupal\jsonapi\Configuration\ResourceConfig $resource_config */ $resource_config = $context['resource_config']; $entity_type_id = $resource_config->getEntityTypeId(); - $bundle_id = $resource_config->getBundleId(); + $bundle_id = $resource_config->getBundle(); $bundle_key = $this->entityTypeManager->getDefinition($entity_type_id) ->getKey('bundle'); if ($bundle_key && $bundle_id) { diff --git a/src/Normalizer/EntityReferenceFieldNormalizer.php b/src/Normalizer/EntityReferenceFieldNormalizer.php index d786165..7002776 100644 --- a/src/Normalizer/EntityReferenceFieldNormalizer.php +++ b/src/Normalizer/EntityReferenceFieldNormalizer.php @@ -4,11 +4,10 @@ namespace Drupal\jsonapi\Normalizer; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityRepositoryInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\EntityReferenceFieldItemListInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Field\TypedData\FieldItemDataDefinition; -use Drupal\jsonapi\Configuration\ResourceManagerInterface; +use Drupal\jsonapi\Configuration\ResourceManager; use Drupal\jsonapi\Resource\EntityCollection; use Drupal\jsonapi\Error\SerializableHttpException; use Drupal\jsonapi\LinkManager\LinkManagerInterface; @@ -63,12 +62,12 @@ class EntityReferenceFieldNormalizer extends FieldNormalizer implements Denormal * The entity field manager. * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $plugin_manager * The plugin manager for fields. - * @param \Drupal\jsonapi\Configuration\ResourceManagerInterface $resource_manager + * @param \Drupal\jsonapi\Configuration\ResourceManager $resource_manager * The resource manager. * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository * The entity repository. */ - public function __construct(LinkManagerInterface $link_manager, EntityFieldManagerInterface $field_manager, FieldTypePluginManagerInterface $plugin_manager, ResourceManagerInterface $resource_manager, EntityRepositoryInterface $entity_repository) { + public function __construct(LinkManagerInterface $link_manager, EntityFieldManagerInterface $field_manager, FieldTypePluginManagerInterface $plugin_manager, ResourceManager $resource_manager, EntityRepositoryInterface $entity_repository) { $this->linkManager = $link_manager; $this->fieldManager = $field_manager; $this->pluginManager = $plugin_manager; @@ -103,7 +102,7 @@ class EntityReferenceFieldNormalizer extends FieldNormalizer implements Denormal $entity_type_id = $context['resource_config']->getEntityTypeId(); $field_definitions = $this->fieldManager->getFieldDefinitions( $entity_type_id, - $context['resource_config']->getBundleId() + $context['resource_config']->getBundle() ); if (empty($context['related']) || empty($field_definitions[$context['related']])) { throw new SerializableHttpException(400, 'Invalid or missing related field.'); diff --git a/src/Normalizer/NormalizerBase.php b/src/Normalizer/NormalizerBase.php index 2e4f0d4..4e83083 100644 --- a/src/Normalizer/NormalizerBase.php +++ b/src/Normalizer/NormalizerBase.php @@ -21,7 +21,7 @@ abstract class NormalizerBase extends SerializationNormalizerBase { /** * The resource manager. * - * @var \Drupal\jsonapi\Configuration\ResourceManagerInterface + * @var \Drupal\jsonapi\Configuration\ResourceManager */ protected $resourceManager; diff --git a/src/Normalizer/Relationship.php b/src/Normalizer/Relationship.php index c1cb5ac..e2b27e1 100644 --- a/src/Normalizer/Relationship.php +++ b/src/Normalizer/Relationship.php @@ -6,7 +6,7 @@ use Drupal\Core\Access\AccessibleInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Session\AccountInterface; -use Drupal\jsonapi\Configuration\ResourceManagerInterface; +use Drupal\jsonapi\Configuration\ResourceManager; use Drupal\jsonapi\Resource\EntityCollectionInterface; /** @@ -44,7 +44,7 @@ class Relationship implements RelationshipInterface, AccessibleInterface { /** * The resource manager. * - * @var \Drupal\jsonapi\Configuration\ResourceManagerInterface + * @var \Drupal\jsonapi\Configuration\ResourceManager */ protected $resourceManager; @@ -58,7 +58,7 @@ class Relationship implements RelationshipInterface, AccessibleInterface { /** * Relationship constructor. * - * @param \Drupal\jsonapi\Configuration\ResourceManagerInterface $resource_manager + * @param \Drupal\jsonapi\Configuration\ResourceManager $resource_manager * The resource manager. * @param string $field_name * The name of the relationship. @@ -71,7 +71,7 @@ class Relationship implements RelationshipInterface, AccessibleInterface { * @param string $target_key * The property name of the relationship id. */ - public function __construct(ResourceManagerInterface $resource_manager, $field_name, $cardinality = FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, EntityCollectionInterface $entities, EntityInterface $host_entity, $target_key = 'target_id') { + public function __construct(ResourceManager $resource_manager, $field_name, $cardinality = FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, EntityCollectionInterface $entities, EntityInterface $host_entity, $target_key = 'target_id') { $this->resourceManager = $resource_manager; $this->propertyName = $field_name; $this->cardinality = $cardinality; diff --git a/src/Normalizer/RelationshipItem.php b/src/Normalizer/RelationshipItem.php index 999d541..4f3fdec 100644 --- a/src/Normalizer/RelationshipItem.php +++ b/src/Normalizer/RelationshipItem.php @@ -3,7 +3,7 @@ namespace Drupal\jsonapi\Normalizer; use Drupal\Core\Entity\EntityInterface; -use Drupal\jsonapi\Configuration\ResourceManagerInterface; +use Drupal\jsonapi\Configuration\ResourceManager; class RelationshipItem implements RelationshipItemInterface { @@ -24,7 +24,7 @@ class RelationshipItem implements RelationshipItemInterface { /** * The target resource config. * - * @param \Drupal\jsonapi\Configuration\ResourceConfigInterface + * @param \Drupal\jsonapi\Configuration\ResourceConfig */ protected $targetResourceConfig; @@ -38,7 +38,7 @@ class RelationshipItem implements RelationshipItemInterface { /** * Relationship item constructor. * - * @param \Drupal\jsonapi\Configuration\ResourceManagerInterface $resource_manager + * @param \Drupal\jsonapi\Configuration\ResourceManager $resource_manager * The resource manager. * @param \Drupal\Core\Entity\EntityInterface $target_entity * The entity this relationship points to. @@ -47,7 +47,7 @@ class RelationshipItem implements RelationshipItemInterface { * @param string $target_key * The key name of the target relationship. */ - public function __construct(ResourceManagerInterface $resource_manager, EntityInterface $target_entity, RelationshipInterface $parent, $target_key = 'target_id') { + public function __construct(ResourceManager $resource_manager, EntityInterface $target_entity, RelationshipInterface $parent, $target_key = 'target_id') { $this->targetResourceConfig = $resource_manager->get( $target_entity->getEntityTypeId(), $target_entity->bundle() diff --git a/src/Normalizer/RelationshipItemNormalizer.php b/src/Normalizer/RelationshipItemNormalizer.php index 338f2a7..4b621a0 100644 --- a/src/Normalizer/RelationshipItemNormalizer.php +++ b/src/Normalizer/RelationshipItemNormalizer.php @@ -5,7 +5,7 @@ namespace Drupal\jsonapi\Normalizer; use Drupal\Core\Cache\RefinableCacheableDependencyInterface; use Drupal\Core\Cache\RefinableCacheableDependencyTrait; use Drupal\Core\Entity\EntityInterface; -use Drupal\jsonapi\Configuration\ResourceManagerInterface; +use Drupal\jsonapi\Configuration\ResourceManager; use Drupal\jsonapi\Resource\EntityResource; use Drupal\serialization\EntityResolver\UuidReferenceInterface; @@ -28,7 +28,7 @@ class RelationshipItemNormalizer extends FieldItemNormalizer implements UuidRefe /** * The manager for resource configuration. * - * @var \Drupal\jsonapi\Configuration\ResourceManagerInterface + * @var \Drupal\jsonapi\Configuration\ResourceManager */ protected $resourceManager; @@ -42,12 +42,12 @@ class RelationshipItemNormalizer extends FieldItemNormalizer implements UuidRefe /** * Instantiates a RelationshipItemNormalizer object. * - * @param \Drupal\jsonapi\Configuration\ResourceManagerInterface $resource_manager + * @param \Drupal\jsonapi\Configuration\ResourceManager $resource_manager * The resource manager. * @param \Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer $jsonapi_document_toplevel_normalizer * The document root normalizer for the include. */ - public function __construct(ResourceManagerInterface $resource_manager, JsonApiDocumentTopLevelNormalizer $jsonapi_document_toplevel_normalizer) { + public function __construct(ResourceManager $resource_manager, JsonApiDocumentTopLevelNormalizer $jsonapi_document_toplevel_normalizer) { $this->resourceManager = $resource_manager; $this->jsonapiDocumentToplevelNormalizer = $jsonapi_document_toplevel_normalizer; } diff --git a/src/Normalizer/RelationshipNormalizer.php b/src/Normalizer/RelationshipNormalizer.php index 370557b..41bb30b 100644 --- a/src/Normalizer/RelationshipNormalizer.php +++ b/src/Normalizer/RelationshipNormalizer.php @@ -3,7 +3,7 @@ namespace Drupal\jsonapi\Normalizer; use Drupal\Core\Entity\EntityInterface; -use Drupal\jsonapi\Configuration\ResourceManagerInterface; +use Drupal\jsonapi\Configuration\ResourceManager; use Drupal\jsonapi\LinkManager\LinkManagerInterface; use Symfony\Component\Serializer\Exception\UnexpectedValueException; @@ -26,7 +26,7 @@ class RelationshipNormalizer extends NormalizerBase { /** * The manager for resource configuration. * - * @var \Drupal\jsonapi\Configuration\ResourceManagerInterface + * @var \Drupal\jsonapi\Configuration\ResourceManager */ protected $resourceManager; @@ -40,12 +40,12 @@ class RelationshipNormalizer extends NormalizerBase { /** * RelationshipNormalizer constructor. * - * @param \Drupal\jsonapi\Configuration\ResourceManagerInterface $resource_manager + * @param \Drupal\jsonapi\Configuration\ResourceManager $resource_manager * The resource manager. * @param \Drupal\jsonapi\LinkManager\LinkManagerInterface $link_manager * The link manager. */ - public function __construct(ResourceManagerInterface $resource_manager, LinkManagerInterface $link_manager) { + public function __construct(ResourceManager $resource_manager, LinkManagerInterface $link_manager) { $this->resourceManager = $resource_manager; $this->linkManager = $link_manager; } diff --git a/src/Normalizer/Value/RelationshipNormalizerValue.php b/src/Normalizer/Value/RelationshipNormalizerValue.php index 88e8ffa..b2611e5 100644 --- a/src/Normalizer/Value/RelationshipNormalizerValue.php +++ b/src/Normalizer/Value/RelationshipNormalizerValue.php @@ -19,7 +19,7 @@ class RelationshipNormalizerValue extends FieldNormalizerValue implements Relati /** * The resource config for the link generation. * - * @var \Drupal\jsonapi\Configuration\ResourceConfigInterface + * @var \Drupal\jsonapi\Configuration\ResourceConfig */ protected $resourceConfig; diff --git a/src/RequestHandler.php b/src/RequestHandler.php index 99eca27..6d6c177 100644 --- a/src/RequestHandler.php +++ b/src/RequestHandler.php @@ -259,7 +259,7 @@ class RequestHandler implements ContainerAwareInterface, ContainerInjectionInter * The instantiated resource. */ protected function resourceFactory(Route $route, CurrentContextInterface $current_context) { - /** @var \Drupal\jsonapi\Configuration\ResourceManagerInterface $resource_manager */ + /** @var \Drupal\jsonapi\Configuration\ResourceManager $resource_manager */ $resource_manager = $this->container->get('jsonapi.resource.manager'); /* @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ $entity_type_manager = $this->container->get('entity_type.manager'); diff --git a/src/Resource/EntityResource.php b/src/Resource/EntityResource.php index d00a70e..3b8d99b 100644 --- a/src/Resource/EntityResource.php +++ b/src/Resource/EntityResource.php @@ -14,7 +14,7 @@ use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Field\EntityReferenceFieldItemListInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem; -use Drupal\jsonapi\Configuration\ResourceConfigInterface; +use Drupal\jsonapi\Configuration\ResourceConfig; use Drupal\jsonapi\Error\SerializableHttpException; use Drupal\jsonapi\Error\UnprocessableHttpEntityException; use Drupal\jsonapi\Query\QueryBuilderInterface; @@ -35,7 +35,7 @@ class EntityResource implements EntityResourceInterface { /** * The resource config. * - * @var \Drupal\jsonapi\Configuration\ResourceConfigInterface + * @var \Drupal\jsonapi\Configuration\ResourceConfig */ protected $resourceConfig; @@ -77,7 +77,7 @@ class EntityResource implements EntityResourceInterface { /** * Instantiates a EntityResource object. * - * @param \Drupal\jsonapi\Configuration\ResourceConfigInterface $resource_config + * @param \Drupal\jsonapi\Configuration\ResourceConfig $resource_config * The configuration for the resource. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager. @@ -90,7 +90,7 @@ class EntityResource implements EntityResourceInterface { * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $plugin_manager * The plugin manager for fields. */ - public function __construct(ResourceConfigInterface $resource_config, EntityTypeManagerInterface $entity_type_manager, QueryBuilderInterface $query_builder, EntityFieldManagerInterface $field_manager, CurrentContextInterface $current_context, FieldTypePluginManagerInterface $plugin_manager) { + public function __construct(ResourceConfig $resource_config, EntityTypeManagerInterface $entity_type_manager, QueryBuilderInterface $query_builder, EntityFieldManagerInterface $field_manager, CurrentContextInterface $current_context, FieldTypePluginManagerInterface $plugin_manager) { $this->resourceConfig = $resource_config; $this->entityTypeManager = $entity_type_manager; $this->queryBuilder = $query_builder; @@ -433,7 +433,7 @@ class EntityResource implements EntityResourceInterface { $query = $this->queryBuilder->newQuery($entity_type, $params); // Limit this query to the bundle type for this resource. - $bundle_id = $this->resourceConfig->getBundleId(); + $bundle_id = $this->resourceConfig->getBundle(); if ($bundle_id && ($bundle_key = $entity_type->getKey('bundle'))) { $query->condition( $bundle_key, $bundle_id diff --git a/src/Routing/Routes.php b/src/Routing/Routes.php index 715e2a8..433b996 100644 --- a/src/Routing/Routes.php +++ b/src/Routing/Routes.php @@ -5,7 +5,7 @@ namespace Drupal\jsonapi\Routing; use Drupal\Core\Authentication\AuthenticationCollectorInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Field\EntityReferenceFieldItemList; -use Drupal\jsonapi\Configuration\ResourceManagerInterface; +use Drupal\jsonapi\Configuration\ResourceManager; use Drupal\jsonapi\Resource\JsonApiDocumentTopLevel; use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -52,12 +52,12 @@ class Routes implements ContainerInjectionInterface { /** * Instantiates a Routes object. * - * @param \Drupal\jsonapi\Configuration\ResourceManagerInterface $resource_manager + * @param \Drupal\jsonapi\Configuration\ResourceManager $resource_manager * The resource manager. * @param \Drupal\Core\Authentication\AuthenticationCollectorInterface $auth_collector * The resource manager. */ - public function __construct(ResourceManagerInterface $resource_manager, AuthenticationCollectorInterface $auth_collector) { + public function __construct(ResourceManager $resource_manager, AuthenticationCollectorInterface $auth_collector) { $this->resourceManager = $resource_manager; $this->authCollector = $auth_collector; } @@ -66,7 +66,7 @@ class Routes implements ContainerInjectionInterface { * {@inheritdoc} */ public static function create(ContainerInterface $container) { - /* @var \Drupal\jsonapi\Configuration\ResourceManagerInterface $resource_manager */ + /* @var \Drupal\jsonapi\Configuration\ResourceManager $resource_manager */ $resource_manager = $container->get('jsonapi.resource.manager'); /* @var \Drupal\Core\Authentication\AuthenticationCollectorInterface $auth_collector */ $auth_collector = $container->get('authentication_collector'); @@ -97,7 +97,7 @@ class Routes implements ContainerInjectionInterface { $route_collection = (new Route('/jsonapi' . $resource_config->getPath())) ->addDefaults($defaults) ->setRequirement('_entity_type', $resource_config->getEntityTypeId()) - ->setRequirement('_bundle', $resource_config->getBundleId()) + ->setRequirement('_bundle', $resource_config->getBundle()) ->setRequirement('_permission', 'access content') ->setRequirement('_format', 'api_json') ->setRequirement('_custom_parameter_names', 'TRUE') @@ -111,7 +111,7 @@ class Routes implements ContainerInjectionInterface { $route_individual = (new Route('/jsonapi' . sprintf('%s/{%s}', $resource_config->getPath(), $resource_config->getEntityTypeId()))) ->addDefaults($defaults) ->setRequirement('_entity_type', $resource_config->getEntityTypeId()) - ->setRequirement('_bundle', $resource_config->getBundleId()) + ->setRequirement('_bundle', $resource_config->getBundle()) ->setRequirement('_permission', 'access content') ->setRequirement('_format', 'api_json') ->setRequirement('_custom_parameter_names', 'TRUE') @@ -126,7 +126,7 @@ class Routes implements ContainerInjectionInterface { $route_related = (new Route('/jsonapi' . sprintf('%s/{%s}/{related}', $resource_config->getPath(), $resource_config->getEntityTypeId()))) ->addDefaults($defaults) ->setRequirement('_entity_type', $resource_config->getEntityTypeId()) - ->setRequirement('_bundle', $resource_config->getBundleId()) + ->setRequirement('_bundle', $resource_config->getBundle()) ->setRequirement('_permission', 'access content') ->setRequirement('_format', 'api_json') ->setRequirement('_custom_parameter_names', 'TRUE') @@ -140,7 +140,7 @@ class Routes implements ContainerInjectionInterface { $route_relationship = (new Route('/jsonapi' . sprintf('%s/{%s}/relationships/{related}', $resource_config->getPath(), $resource_config->getEntityTypeId()))) ->addDefaults($defaults + ['_on_relationship' => TRUE]) ->setRequirement('_entity_type', $resource_config->getEntityTypeId()) - ->setRequirement('_bundle', $resource_config->getBundleId()) + ->setRequirement('_bundle', $resource_config->getBundle()) ->setRequirement('_permission', 'access content') ->setRequirement('_format', 'api_json') ->setRequirement('_custom_parameter_names', 'TRUE') diff --git a/tests/src/Kernel/Configuration/ResourceManagerTest.php b/tests/src/Kernel/Configuration/ResourceManagerTest.php index 6ca6095..4e34e25 100644 --- a/tests/src/Kernel/Configuration/ResourceManagerTest.php +++ b/tests/src/Kernel/Configuration/ResourceManagerTest.php @@ -2,8 +2,7 @@ namespace Drupal\Tests\jsonapi\Kernel\Configuration; -use Drupal\jsonapi\Configuration\ResourceConfigInterface; -use Drupal\jsonapi\Configuration\ResourceManager; +use Drupal\jsonapi\Configuration\ResourceConfig; use Drupal\KernelTests\KernelTestBase; use Drupal\node\Entity\NodeType; @@ -32,7 +31,7 @@ class ResourceManagerTest extends KernelTestBase { /** * The entity resource under test. * - * @var \Drupal\jsonapi\Configuration\ResourceManagerInterface + * @var \Drupal\jsonapi\Configuration\ResourceManager */ protected $resourceManager; @@ -65,12 +64,12 @@ class ResourceManagerTest extends KernelTestBase { // Make sure that there are resources being created. $all = $this->resourceManager->all(); $this->assertNotEmpty($all); - array_walk($all, function (ResourceConfigInterface $resource_config) { + array_walk($all, function (ResourceConfig $resource_config) { $this->assertNotEmpty($resource_config->getDeserializationTargetClass()); $this->assertNotEmpty($resource_config->getEntityTypeId()); $this->assertNotEmpty($resource_config->getTypeName()); $path = $resource_config->getPath(); - if (!$resource_config->getBundleId()) { + if (!$resource_config->getBundle()) { $this->assertCount(1, explode('/', ltrim($path, '/'))); } $this->assertNotEmpty($path); @@ -84,10 +83,10 @@ class ResourceManagerTest extends KernelTestBase { public function testGet($entity_type_id, $bundle_id, $entity_class) { // Make sure that there are resources being created. $resource_config = $this->resourceManager->get($entity_type_id, $bundle_id); - $this->assertInstanceOf(ResourceConfigInterface::class, $resource_config); + $this->assertInstanceOf(ResourceConfig::class, $resource_config); $this->assertSame($entity_class, $resource_config->getDeserializationTargetClass()); $this->assertSame($entity_type_id, $resource_config->getEntityTypeId()); - $this->assertSame($bundle_id, $resource_config->getBundleId()); + $this->assertSame($bundle_id, $resource_config->getBundle()); $this->assertSame('/' . $entity_type_id . '/' . $bundle_id, $resource_config->getPath()); $this->assertSame($entity_type_id . '--' . $bundle_id, $resource_config->getTypeName()); } diff --git a/tests/src/Unit/Context/CurrentContextTest.php b/tests/src/Unit/Context/CurrentContextTest.php index d143432..20872f5 100644 --- a/tests/src/Unit/Context/CurrentContextTest.php +++ b/tests/src/Unit/Context/CurrentContextTest.php @@ -5,7 +5,7 @@ namespace Drupal\Tests\jsonapi\Unit\Context; use Drupal\Core\Routing\CurrentRouteMatch; use Drupal\jsonapi\Context\CurrentContext; use Drupal\jsonapi\Configuration\ResourceConfig; -use Drupal\jsonapi\Configuration\ResourceManagerInterface; +use Drupal\jsonapi\Configuration\ResourceManager; use Drupal\jsonapi\Routing\Param\Filter; use Drupal\jsonapi\Routing\Param\Sort; use Drupal\jsonapi\Routing\Param\OffsetPage; @@ -43,7 +43,7 @@ class CurrentContextTest extends UnitTestCase { /** * A mock for the current route. * - * @var \Drupal\jsonapi\Configuration\ResourceManagerInterface + * @var \Drupal\jsonapi\Configuration\ResourceManager */ protected $resourceManager; @@ -81,7 +81,7 @@ class CurrentContextTest extends UnitTestCase { ); // Create a mock for the ResourceManager service. - $resource_prophecy = $this->prophesize(ResourceManagerInterface::CLASS); + $resource_prophecy = $this->prophesize(ResourceManager::CLASS); $resource_config = new ResourceConfig('node', 'article', NodeInterface::class); $resource_prophecy->get('node', 'article')->willReturn($resource_config); $this->resourceManager = $resource_prophecy->reveal(); diff --git a/tests/src/Unit/Normalizer/ConfigEntityNormalizerTest.php b/tests/src/Unit/Normalizer/ConfigEntityNormalizerTest.php index 6420001..8537c61 100644 --- a/tests/src/Unit/Normalizer/ConfigEntityNormalizerTest.php +++ b/tests/src/Unit/Normalizer/ConfigEntityNormalizerTest.php @@ -5,7 +5,7 @@ namespace Drupal\Tests\jsonapi\Unit\Normalizer; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\jsonapi\Configuration\ResourceConfig; -use Drupal\jsonapi\Configuration\ResourceManagerInterface; +use Drupal\jsonapi\Configuration\ResourceManager; use Drupal\jsonapi\Normalizer\ConfigEntityNormalizer; use Drupal\jsonapi\LinkManager\LinkManagerInterface; use Drupal\jsonapi\Context\CurrentContextInterface; @@ -41,7 +41,7 @@ class ConfigEntityNormalizerTest extends UnitTestCase { $current_context_manager->isOnRelationship()->willReturn(FALSE); - $resource_manager = $this->prophesize(ResourceManagerInterface::class); + $resource_manager = $this->prophesize(ResourceManager::class); $resource_manager->get(Argument::type('string'), Argument::type('string')) ->willReturn(new ResourceConfig('dolor', 'sid', NULL)); $current_context_manager->getResourceManager()->willReturn( diff --git a/tests/src/Unit/Normalizer/EntityReferenceFieldNormalizerTest.php b/tests/src/Unit/Normalizer/EntityReferenceFieldNormalizerTest.php index ae48073..987f7e5 100644 --- a/tests/src/Unit/Normalizer/EntityReferenceFieldNormalizerTest.php +++ b/tests/src/Unit/Normalizer/EntityReferenceFieldNormalizerTest.php @@ -11,7 +11,7 @@ use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Field\TypedData\FieldItemDataDefinition; use Drupal\field\Entity\FieldConfig; use Drupal\jsonapi\Configuration\ResourceConfig; -use Drupal\jsonapi\Configuration\ResourceManagerInterface; +use Drupal\jsonapi\Configuration\ResourceManager; use Drupal\jsonapi\Normalizer\EntityReferenceFieldNormalizer; use Drupal\jsonapi\LinkManager\LinkManagerInterface; use Drupal\Tests\UnitTestCase; @@ -72,7 +72,7 @@ class EntityReferenceFieldNormalizerTest extends UnitTestCase { Argument::type('string'), Argument::type('array') )->willReturnArgument(2); - $resource_manager = $this->prophesize(ResourceManagerInterface::class); + $resource_manager = $this->prophesize(ResourceManager::class); $resource_manager->get('fake_entity_type', 'dummy_bundle') ->willReturn(new ResourceConfig('lorem', 'dummy_bundle', NULL)); diff --git a/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php b/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php index e242867..c33d535 100644 --- a/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php +++ b/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php @@ -7,7 +7,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\jsonapi\Configuration\ResourceConfig; -use Drupal\jsonapi\Configuration\ResourceManagerInterface; +use Drupal\jsonapi\Configuration\ResourceManager; use Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer; use Drupal\jsonapi\LinkManager\LinkManagerInterface; use Drupal\jsonapi\Context\CurrentContextInterface; @@ -33,7 +33,7 @@ class JsonApiDocumentTopLevelNormalizerTest extends UnitTestCase { /** * The resource config for the context. * - * @var \Drupal\jsonapi\Configuration\ResourceConfigInterface + * @var \Drupal\jsonapi\Configuration\ResourceConfig */ protected $resourceConfig; @@ -64,7 +64,7 @@ class JsonApiDocumentTopLevelNormalizerTest extends UnitTestCase { $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class); $entity_type_manager->getStorage('node') ->willReturn($entity_storage->reveal()); - $resource_manager = $this->prophesize(ResourceManagerInterface::class); + $resource_manager = $this->prophesize(ResourceManager::class); $current_context_manager->getResourceManager()->willReturn($resource_manager->reveal()); $current_route = $this->prophesize(Route::class); diff --git a/tests/src/Unit/Routing/RoutesTest.php b/tests/src/Unit/Routing/RoutesTest.php index 1cd8c4b..0ed9068 100644 --- a/tests/src/Unit/Routing/RoutesTest.php +++ b/tests/src/Unit/Routing/RoutesTest.php @@ -5,7 +5,7 @@ namespace Drupal\Tests\jsonapi\Unit\Routing; use Drupal\Core\Authentication\AuthenticationCollectorInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\jsonapi\Configuration\ResourceConfig; -use Drupal\jsonapi\Configuration\ResourceManagerInterface; +use Drupal\jsonapi\Configuration\ResourceManager; use Drupal\jsonapi\Routing\Routes; use Drupal\Tests\UnitTestCase; use Symfony\Cmf\Component\Routing\RouteObjectInterface; @@ -35,7 +35,7 @@ class RoutesTest extends UnitTestCase { protected function setUp() { parent::setUp(); // Mock the resource manager to have some resources available. - $resource_manager = $this->prophesize(ResourceManagerInterface::class); + $resource_manager = $this->prophesize(ResourceManager::class); $resource_manager->all()->willReturn([new ResourceConfig('entity_type_1', 'bundle_1_1', EntityInterface::class)]); $container = $this->prophesize(ContainerInterface::class); $container->get('jsonapi.resource.manager')->willReturn($resource_manager->reveal());