src/Configuration/ResourceConfig.php | 8 ++++---- src/Configuration/ResourceManager.php | 4 ++-- src/Context/CurrentContext.php | 4 ++-- src/Normalizer/ConfigEntityNormalizer.php | 2 +- src/Normalizer/EntityNormalizer.php | 20 ++++++++++---------- src/Normalizer/EntityReferenceFieldNormalizer.php | 4 ++-- src/Resource/EntityResource.php | 6 +++--- .../src/Kernel/Configuration/ResourceManagerTest.php | 8 ++++---- .../JsonApiDocumentTopLevelNormalizerTest.php | 12 ++++++------ tests/src/Kernel/Resource/EntityResourceTest.php | 10 +++++----- 10 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Configuration/ResourceConfig.php b/src/Configuration/ResourceConfig.php index 16118ce..84558f0 100644 --- a/src/Configuration/ResourceConfig.php +++ b/src/Configuration/ResourceConfig.php @@ -76,14 +76,14 @@ class ResourceConfig implements ResourceConfigInterface { * * @param string $entity_type_id * An entity type ID. - * @param string $bundle - * A bundle. + * @param string $bundle_id + * A bundle ID. * @param string $deserialization_target_class * The deserialization target class. */ - public function __construct($entity_type_id, $bundle, $deserialization_target_class) { + public function __construct($entity_type_id, $bundle_id, $deserialization_target_class) { $this->entityTypeId = $entity_type_id; - $this->bundle = $bundle; + $this->bundle = $bundle_id; $this->deserializationTargetClass = $deserialization_target_class; $this->typeName = sprintf('%s--%s', $this->entityTypeId, $this->bundle); diff --git a/src/Configuration/ResourceManager.php b/src/Configuration/ResourceManager.php index fb18f60..d8c23b2 100644 --- a/src/Configuration/ResourceManager.php +++ b/src/Configuration/ResourceManager.php @@ -73,12 +73,12 @@ class ResourceManager implements ResourceManagerInterface { /** * {@inheritdoc} */ - public function get($entity_type_id, $bundle) { + 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->getBundle() == $bundle) { + if ($resource->getEntityTypeId() == $entity_type_id && $resource->getBundle() == $bundle_id) { return $resource; } } diff --git a/src/Context/CurrentContext.php b/src/Context/CurrentContext.php index 299eac2..4f8800c 100644 --- a/src/Context/CurrentContext.php +++ b/src/Context/CurrentContext.php @@ -68,9 +68,9 @@ class CurrentContext implements CurrentContextInterface { if (!isset($this->resourceConfig)) { $route = $this->routeMatch->getRouteObject(); $entity_type_id = $route->getRequirement('_entity_type'); - $bundle = $route->getRequirement('_bundle'); + $bundle_id = $route->getRequirement('_bundle'); $this->resourceConfig = $this->resourceManager - ->get($entity_type_id, $bundle); + ->get($entity_type_id, $bundle_id); } return $this->resourceConfig; diff --git a/src/Normalizer/ConfigEntityNormalizer.php b/src/Normalizer/ConfigEntityNormalizer.php index 1029fcc..153ef98 100644 --- a/src/Normalizer/ConfigEntityNormalizer.php +++ b/src/Normalizer/ConfigEntityNormalizer.php @@ -23,7 +23,7 @@ class ConfigEntityNormalizer extends EntityNormalizer { /** * {@inheritdoc} */ - protected function getFields($entity, $bundle) { + protected function getFields($entity, $bundle_id) { /* @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */ return $entity->toArray(); } diff --git a/src/Normalizer/EntityNormalizer.php b/src/Normalizer/EntityNormalizer.php index 20eb3e1..a40a257 100644 --- a/src/Normalizer/EntityNormalizer.php +++ b/src/Normalizer/EntityNormalizer.php @@ -90,16 +90,16 @@ 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 = $context['resource_config']->getBundle(); + $bundle_id = $context['resource_config']->getBundle(); if (!empty($context['sparse_fieldset'][$resource_type])) { $field_names = $context['sparse_fieldset'][$resource_type]; } else { - $field_names = $this->getFieldNames($entity, $bundle); + $field_names = $this->getFieldNames($entity, $bundle_id); } /* @var Value\FieldNormalizerValueInterface[] $normalizer_values */ $normalizer_values = []; - foreach ($this->getFields($entity, $bundle) as $field_name => $field) { + foreach ($this->getFields($entity, $bundle_id) as $field_name => $field) { if (!in_array($field_name, $field_names)) { continue; } @@ -143,11 +143,11 @@ class EntityNormalizer extends NormalizerBase implements DenormalizerInterface, /* @var \Drupal\jsonapi\Configuration\ResourceConfigInterface $resource_config */ $resource_config = $context['resource_config']; $entity_type_id = $resource_config->getEntityTypeId(); - $bundle = $resource_config->getBundle(); + $bundle_id = $resource_config->getBundle(); $bundle_key = $this->entityTypeManager->getDefinition($entity_type_id) ->getKey('bundle'); - if ($bundle_key && $bundle) { - $data[$bundle_key] = $bundle; + if ($bundle_key && $bundle_id) { + $data[$bundle_key] = $bundle_id; } return $this->entityTypeManager->getStorage($entity_type_id) @@ -163,9 +163,9 @@ class EntityNormalizer extends NormalizerBase implements DenormalizerInterface, * @return string[] * The field names. */ - protected function getFieldNames($entity, $bundle) { + protected function getFieldNames($entity, $bundle_id) { /* @var \Drupal\Core\Entity\ContentEntityInterface $entity */ - return array_keys($this->getFields($entity, $bundle)); + return array_keys($this->getFields($entity, $bundle_id)); } /** @@ -173,13 +173,13 @@ class EntityNormalizer extends NormalizerBase implements DenormalizerInterface, * * @param mixed $entity * The entity. - * @param string $bundle + * @param string $bundle_id * The bundle id. * * @return array * The fields. */ - protected function getFields($entity, $bundle) { + protected function getFields($entity, $bundle_id) { /* @var \Drupal\Core\Entity\ContentEntityInterface $entity */ return $entity->getFields(); } diff --git a/src/Normalizer/EntityReferenceFieldNormalizer.php b/src/Normalizer/EntityReferenceFieldNormalizer.php index 59c4cd1..c04a76a 100644 --- a/src/Normalizer/EntityReferenceFieldNormalizer.php +++ b/src/Normalizer/EntityReferenceFieldNormalizer.php @@ -192,9 +192,9 @@ class EntityReferenceFieldNormalizer extends FieldNormalizer implements Denormal $target_bundles = empty($handler_settings['target_bundles']) ? [] : $handler_settings['target_bundles']; - return array_map(function ($target_bundle) use ($target_entity_id) { + return array_map(function ($target_bundle_id) use ($target_entity_id) { return $this->resourceManager - ->get($target_entity_id, $target_bundle) + ->get($target_entity_id, $target_bundle_id) ->getTypeName(); }, $target_bundles); } diff --git a/src/Resource/EntityResource.php b/src/Resource/EntityResource.php index 5121c05..66683ad 100644 --- a/src/Resource/EntityResource.php +++ b/src/Resource/EntityResource.php @@ -433,10 +433,10 @@ class EntityResource implements EntityResourceInterface { $query = $this->queryBuilder->newQuery($entity_type, $params); // Limit this query to the bundle type for this resource. - $bundle = $this->resourceConfig->getBundle(); - if ($bundle && ($bundle_key = $entity_type->getKey('bundle'))) { + $bundle_id = $this->resourceConfig->getBundle(); + if ($bundle_id && ($bundle_key = $entity_type->getKey('bundle'))) { $query->condition( - $bundle_key, $bundle + $bundle_key, $bundle_id ); } diff --git a/tests/src/Kernel/Configuration/ResourceManagerTest.php b/tests/src/Kernel/Configuration/ResourceManagerTest.php index 5a8ae85..6c427f4 100644 --- a/tests/src/Kernel/Configuration/ResourceManagerTest.php +++ b/tests/src/Kernel/Configuration/ResourceManagerTest.php @@ -76,14 +76,14 @@ class ResourceManagerTest extends KernelTestBase { * @covers ::get * @dataProvider getProvider */ - public function testGet($entity_type_id, $bundle, $entity_class) { + 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); + $resource_config = $this->resourceManager->get($entity_type_id, $bundle_id); $this->assertInstanceOf(ResourceConfigInterface::class, $resource_config); $this->assertSame($entity_class, $resource_config->getDeserializationTargetClass()); $this->assertSame($entity_type_id, $resource_config->getEntityTypeId()); - $this->assertSame($bundle, $resource_config->getBundle()); - $this->assertSame($entity_type_id . '--' . $bundle, $resource_config->getTypeName()); + $this->assertSame($bundle_id, $resource_config->getBundle()); + $this->assertSame($entity_type_id . '--' . $bundle_id, $resource_config->getTypeName()); } /** diff --git a/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php b/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php index ee19d1a..2834006 100644 --- a/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php +++ b/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php @@ -537,14 +537,14 @@ class JsonApiDocumentTopLevelNormalizerTest extends JsonapiKernelTestBase { * * @param string $entity_type_id * The ID of the entity type. Ex: node. - * @param string $bundle - * The bundle. Ex: article. + * @param string $bundle_id + * The ID of the bundle. Ex: article. * * @return array * A numeric array containing the request and the resource config mocks. */ - protected function generateProphecies($entity_type_id, $bundle, $related_property = NULL) { - $path = sprintf('/%s/%s', $entity_type_id, $bundle); + protected function generateProphecies($entity_type_id, $bundle_id, $related_property = NULL) { + $path = sprintf('/%s/%s', $entity_type_id, $bundle_id); $path = $related_property ? sprintf('%s/%s', $path, $related_property) : $path; @@ -553,7 +553,7 @@ class JsonApiDocumentTopLevelNormalizerTest extends JsonapiKernelTestBase { '_on_relationship' => NULL, ], [ '_entity_type' => $entity_type_id, - '_bundle' => $bundle, + '_bundle' => $bundle_id, ]); $request = new Request([], [], [ RouteObjectInterface::ROUTE_OBJECT => $route, @@ -563,7 +563,7 @@ class JsonApiDocumentTopLevelNormalizerTest extends JsonapiKernelTestBase { $resource_config = new ResourceConfig( $entity_type_id, - $bundle, + $bundle_id, $entity_type_manager->getDefinition($entity_type_id)->getClass() ); diff --git a/tests/src/Kernel/Resource/EntityResourceTest.php b/tests/src/Kernel/Resource/EntityResourceTest.php index f97c7df..e2a393f 100644 --- a/tests/src/Kernel/Resource/EntityResourceTest.php +++ b/tests/src/Kernel/Resource/EntityResourceTest.php @@ -783,17 +783,17 @@ class EntityResourceTest extends JsonapiKernelTestBase { * * @param string $entity_type_id * The entity type ID. - * @param string $bundle - * The bundle. + * @param string $bundle_id + * The bundle ID. * * @return \Drupal\jsonapi\Resource\EntityResourceInterface * The resource. */ - protected function buildEntityResource($entity_type_id, $bundle) { + protected function buildEntityResource($entity_type_id, $bundle_id) { // The fake route. $route = new Route(NULL, [], [ '_entity_type' => $entity_type_id, - '_bundle' => $bundle, + '_bundle' => $bundle_id, ]); // The request. $request = new Request([], [], ['_route_object' => $route]); @@ -808,7 +808,7 @@ class EntityResourceTest extends JsonapiKernelTestBase { $this->container->set('jsonapi.current_context', $current_context); return new EntityResource( - new ResourceConfig($entity_type_id, $bundle, NULL), + new ResourceConfig($entity_type_id, $bundle_id, NULL), $this->container->get('entity_type.manager'), $this->container->get('jsonapi.query_builder'), $this->container->get('entity_field.manager'),