diff -u b/src/Context/FieldResolver.php b/src/Context/FieldResolver.php --- b/src/Context/FieldResolver.php +++ b/src/Context/FieldResolver.php @@ -33,4 +33,18 @@ /** + * The entity bundle information service. + * + * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface + */ + protected $entityTypeBundleInfo; + + /** + * The resource type repository service. + * + * @var \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface + */ + protected $resourceTypeRepository; + + /** * Creates a FieldResolver instance. * @@ -85,7 +99,7 @@ * resolve any aliases and/or abbreviations into a field expression that will * be compatible with the entity query system. * - * @see http://jsonapi.org/recommendations/#urls-reference-document + * @link http://jsonapi.org/recommendations/#urls-reference-document * * Example: * 'uid.field_first_name' -> 'uid.entity.field_first_name'. @@ -156,7 +170,9 @@ * Resolves the internal field name based on a collection of resource types. * * @param string $field_name + * The external field name. * @param \Drupal\jsonapi\ResourceType\ResourceType[] $resource_types + * The resource types from which to get an internal name. * * @return string * The resolved internal name. diff -u b/tests/src/Kernel/Context/FieldResolverTest.php b/tests/src/Kernel/Context/FieldResolverTest.php --- b/tests/src/Kernel/Context/FieldResolverTest.php +++ b/tests/src/Kernel/Context/FieldResolverTest.php @@ -17,6 +17,8 @@ public static $modules = ['entity_test', 'serialization', 'field', 'text']; /** + * The subject under test. + * * @var \Drupal\jsonapi\Context\FieldResolver */ protected $sut; @@ -81,6 +83,13 @@ /** * Expects an error when an invalid field is provided. * + * @param string $entity_type + * The entity type for which to test field resolution. + * @param string $bundle + * The entity bundle for which to test field resolution. + * @param string $external_path + * The external field path to resolve. + * * @covers ::resolveInternal * @dataProvider resolveInternalErrorProvider * @@ -90,13 +99,17 @@ $this->sut->resolveInternal($entity_type, $bundle, $external_path); } + /** + * Provides test cases for ::testResolveInternalError. + */ public function resolveInternalErrorProvider() { return [ // Should fail because none of these bundles have these fields. ['entity_test_with_bundle', 'bundle1', 'host.fail!!.deep'], ['entity_test_with_bundle', 'bundle2', 'field_test_ref2'], ['entity_test_with_bundle', 'bundle1', 'field_test_ref3'], - // Should fail because the nested field don't exist on the targeted resources. + // Should fail because the nested fields don't exist on the targeted + // resource types. ['entity_test_with_bundle', 'bundle1', 'field_test_ref1.field_test1'], ['entity_test_with_bundle', 'bundle1', 'field_test_ref1.field_test2'], ['entity_test_with_bundle', 'bundle1', 'field_test_ref1.field_test_ref1'], @@ -106,6 +119,9 @@ /** * Create a simple bundle. + * + * @param string $name + * The name of the bundle to create. */ protected function makeBundle($name) { EntityTestBundle::create([ @@ -113,7 +129,23 @@ ])->save(); } - protected function makeField($type, $name, $entity_type, $bundles, $storage_settings = [], $config_settings = []) { + /** + * Creates a field for a specified entity type/bundle. + * + * @param string $type + * The field type. + * @param string $name + * The name of the field to create. + * @param string $entity_type + * The entity type to which the field will be attached. + * @param string[] $bundles + * The entity bundles to which the field will be attached. + * @param array $storage_settings + * Custom storage settings for the field. + * @param array $config_settings + * Custom configuration settings for the field. + */ + protected function makeField($type, $name, $entity_type, array $bundles, array $storage_settings = [], array $config_settings = []) { $storage_config = [ 'field_name' => $name, 'type' => $type,