src/Routing/Routes.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Routing/Routes.php b/src/Routing/Routes.php index fd6b81d..ec5fa5a 100644 --- a/src/Routing/Routes.php +++ b/src/Routing/Routes.php @@ -231,13 +231,15 @@ class Routes implements ContainerInjectionInterface { $new_resource_file_upload_route->addDefaults([RouteObjectInterface::CONTROLLER_NAME => 'jsonapi.file_upload:handleFileUploadForNewResource']); $new_resource_file_upload_route->setMethods(['POST']); $new_resource_file_upload_route->setRequirement('_csrf_request_header_token', 'TRUE'); - $routes->add(static::getFileUploadRouteName($resource_type, 'new_resource'), $new_resource_file_upload_route); + $new_resource_file_upload_route->setDefault('file_field_name', $relationship_field_name); + $routes->add(static::getFileUploadRouteName($resource_type, $relationship_field_name, 'new_resource'), $new_resource_file_upload_route); $existing_resource_file_upload_route = new Route("/{$path}/{entity}/{$relationship_field_name}"); $existing_resource_file_upload_route->addDefaults([RouteObjectInterface::CONTROLLER_NAME => 'jsonapi.file_upload:handleFileUploadForExistingResource']); $existing_resource_file_upload_route->setMethods(['POST']); $existing_resource_file_upload_route->setRequirement('_csrf_request_header_token', 'TRUE'); - $routes->add(static::getFileUploadRouteName($resource_type, 'existing_resource'), $existing_resource_file_upload_route); + $existing_resource_file_upload_route->setDefault('file_field_name', $relationship_field_name); + $routes->add(static::getFileUploadRouteName($resource_type, $relationship_field_name, 'existing_resource'), $existing_resource_file_upload_route); // Add entity parameter conversion to every route. $routes->addOptions(['parameters' => ['entity' => ['type' => 'entity:' . $entity_type_id]]]); @@ -413,15 +415,20 @@ class Routes implements ContainerInjectionInterface { * Get a unique route name for the file upload resource type and route type. * * @param \Drupal\jsonapi\ResourceType\ResourceType $resource_type - * The resource type for which the route collection should be created. + * The resource type for which the file upload route should be created. + * @param string $file_field_name + * The file field for which the file upload route should be created. * @param string $route_type - * The route type. E.g. 'individual' or 'collection'. + * The route type. E.g. 'new_resource' or 'existing_resource'. * * @return string * The generated route name. + * + * @todo remove this in favor of getroutename */ - protected static function getFileUploadRouteName(ResourceType $resource_type, $route_type) { - return sprintf('jsonapi.%s.%s.%s', $resource_type->getTypeName(), 'file_upload', $route_type); + protected static function getFileUploadRouteName(ResourceType $resource_type, $file_field_name, $route_type) { + assert($route_type === 'new_resource' || $route_type === 'existing_resource'); + return sprintf('jsonapi.%s.%s.%s.%s', $resource_type->getTypeName(), $file_field_name, 'file_upload', $route_type); } /**