Problem/Motivation
The following error has been reported multiple times:
Argument 2 passed to Drupal\jsonapi\Routing\Routes::Drupal\jsonapi\Routing\{closure}() must be an instance of Drupal\jsonapi\ResourceType\ResourceType, NULL given
The only potential source of this error is in Drupal\jsonapi\ResourceType\ResourceTypeRepository::getRelatableResourceTypesFromFieldDefinition()
:
$has_target_bundles = isset($handler_settings['target_bundles']) && !empty($handler_settings['target_bundles']);
$target_bundles = $has_target_bundles ?
$handler_settings['target_bundles']
: $this->getAllBundlesForEntityType($entity_type_id);
return array_map(function ($target_bundle) use ($entity_type_id, $resource_types) {
$type_name = "$entity_type_id--$target_bundle";
return isset($resource_types[$type_name]) ? $resource_types[$type_name] : NULL;
}, $target_bundles);
The two known reasons that NULL
might be generated is if an entity reference field has handler settings referencing a missing target bundle or the resource type name has been overridden by JSON:API Extras.
Proposed resolution
Neither of these reasons is a bug in JSON:API, per se. Instead, they could be caused by bad configuration, a poorly defined custom base field, or by JSON:API Extras.
In order to help users suffering from those bugs, introduce exceptions that will pinpoint the source of the errors.
User interface changes
Nope.
API changes
Nope.
Data model changes
Nope.
Release notes snippet
N/a