protected function JsonApiGenerator::relatedResourceType in OpenAPI for JSON:API 8.2
Same name and namespace in other branches
- 3.x src/Plugin/openapi/OpenApiGenerator/JsonApiGenerator.php \Drupal\openapi_jsonapi\Plugin\openapi\OpenApiGenerator\JsonApiGenerator::relatedResourceType()
Gets the related Resource Type.
Parameters
string $route_name: The JSON API route name for which the ResourceType is wanted.
\Symfony\Component\Routing\Route $route: The JSON API route for which the ResourceType is wanted.
Return value
\Drupal\jsonapi\ResourceType\ResourceType|null Returns the ResourceType for the related JSON API resource.
4 calls to JsonApiGenerator::relatedResourceType()
- JsonApiGenerator::getEntityResponsesJsonApi in src/
Plugin/ openapi/ OpenApiGenerator/ JsonApiGenerator.php - JsonApiGenerator::getMethodParameters in src/
Plugin/ openapi/ OpenApiGenerator/ JsonApiGenerator.php - Get the parameters array for a method on a route.
- JsonApiGenerator::getRouteMethodDescription in src/
Plugin/ openapi/ OpenApiGenerator/ JsonApiGenerator.php - Gets description of a method on a route.
- JsonApiGenerator::getRouteMethodSummary in src/
Plugin/ openapi/ OpenApiGenerator/ JsonApiGenerator.php - Gets description of a method on a route.
File
- src/
Plugin/ openapi/ OpenApiGenerator/ JsonApiGenerator.php, line 449
Class
- JsonApiGenerator
- Defines an OpenApi Schema Generator for the JsonApi module.
Namespace
Drupal\openapi_jsonapi\Plugin\openapi\OpenApiGeneratorCode
protected function relatedResourceType($route_name, $route) {
if (!in_array($this
->getRoutTypeFromName($route_name), [
'related',
'relationship',
])) {
return NULL;
}
$resource_type = $this
->getResourceType($route_name, $route);
$field_name = explode('.', $route_name)[2];
$target_resource_type = current($resource_type
->getRelatableResourceTypesByField($field_name));
assert(is_a($target_resource_type, ResourceType::class));
return $target_resource_type;
}