nova-flexible-content: File fields "delete" button returns 404

The Delete button under a file field does not work correctly.

image

Nova responds with something like:

DELETE http://example.tld/nova-api/{resource}/{resourceId}/field/2011da1c6d582ce2__image 404 (Not Found)

This is because the fields inside a Flexible field do not exist in the resource’s root fields.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 14
  • Comments: 23 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Hi guys,

Just to clarify, “hard to read” not meaning it’s not good code, it is, meaning it’s hard to keep a mental model in one’s head of all the moving parts and track each variables actual value etc.

If you have not developed a Nova plugin and have not got a handle on the inner workings is quite daunting.

Thanks again for a great tool.

Yup, the issue lies here in FieldDestroyController in the handle method. As @Nyratas pointed out - when Nova tries to find the field by attribute it fails, because the field does not exist in the root.

$field = $resource->updateFields($request)
            ->whereInstanceOf(File::class)
            ->findFieldByAttribute($request->field, function () {
                abort(404);
            });

One of the solutions could be to overwrite the updateFields method on the resource by returning a custom FieldCollection instance which uses a different way to find fields by attribute. This could all be part of the package, you could just include a trait in your resource.

I might give it a go in the coming days.

On second inspection - overriding the availableFields method on the resource and applying a custom instance of the collection should do the trick.

Hi all, Just checking for an update on this, I find it hard to believe on such a great tool this has not been fixed, unless we are doing something wrong. Basically one cannot remove and image without deleting the whole layout and that leaves the assets on disk.

I am looking into it, but code is quite complex. Did anyone sort this?

Looks like something related is happening when you use a Trix field. Getting 404s when adding images to a Flexible layout containing a Trix field.

            Flexible::make('Content')
                ->addLayout('Simple content section', 'wysiwyg', [
                    Text::make('Title'),
                    Trix::make('Content')->withFiles('local')->alwaysShow()
                ]),

A normal Trix upload will post to (eg):

/nova-api/blocks/trix-attachment/content

whereas within a Flexible field, it’s posting to:

/nova-api/blocks/trix-attachment/4dd76ad5528575d4__content

and getting a 404 response.