Problem/Motivation
If the file--file resource has been aliased using JSON:API Extras or #3105318: Add a public API for aliasing resource type names, uploading files fails
"errors": [
{
"title": "Internal Server Error",
"status": "500",
"detail": "Route \\u0022jsonapi.file--file.individual\\u0022 does not exist.",
This is due to a hardcoded string for the resource type name:
// @todo Remove line below in favor of commented line in https://www.drupal.org/project/drupal/issues/2878463.
$self_link = new Link(new CacheableMetadata(), Url::fromRoute('jsonapi.file--file.individual', ['entity' => $file->uuid()]), 'self');
/* $self_link = new Link(new CacheableMetadata(), $this->entity->toUrl('jsonapi'), ['self']); */
$links = new LinkCollection(['self' => $self_link]);
The @todo is irrelevant to this issue (although it'd make life a lot easier.)
Steps to reproduce
Alias file entity resource. Try uploading.
Proposed resolution
Fetch the resource type from the repository.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | cannot_upload_files-3171154-3.patch | 1.62 KB | mglaman |
Issue fork drupal-3171154
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mglamanActually, a few lines down we get the file resource type and could just use the type name from there
Comment #3
mglamanHere is a patch to prevent using a hardcoded resource type name.
Comment #4
mglamanActually, we have \Drupal\jsonapi\Routing\Routes::getRouteName
This code should call that method with the resource type and "individual".
Comment #5
mglamanThis seems like an oversight from #2958554: Allow creation of file entities from binary data via JSON API requests and would be a follow up to address the missing usage of the route name helper method.
Comment #7
kristen polThanks for the issue and patch. I agree with #4 that
Routes::getRouteName()should be used so moving back to needs work. I might try to do this via gitlab so I'll open a fork branch.Comment #9
mglamanComment #10
kristen polThanks for the status change. Not sure doing the patch is gitlab was helpful for me but figured I'd try it once. :)
Comment #12
bbralaI love this change, code it good.
We do need tests for this issue. Preferably a seperate test patch to show the failure, but since the testing methology is change in #3105318: Add a public API for aliasing resource type names perhaps we should wait for that issue.
Comment #13
bbrala