Code Monkey home page Code Monkey logo

Comments (23)

ajarti avatar ajarti commented on July 23, 2024 2

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.

from nova-flexible-content.

element25 avatar element25 commented on July 23, 2024 1

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.

from nova-flexible-content.

ajarti avatar ajarti commented on July 23, 2024 1

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?

from nova-flexible-content.

slovenianGooner avatar slovenianGooner commented on July 23, 2024 1

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.

from nova-flexible-content.

raphcollective avatar raphcollective commented on July 23, 2024

I looked at that issue quickly, the only solution I can think of is to have a FlexibleFile/FlexibleImage field that emulates the same behavior as the original File field but will allow us to change the controller actions called by the vue component. The issue with that solution is that we'll have to track and maintain the same level of functionality than the original Nova field, it's not frequently updated but still.

Does that makes sense or do you have any other idea? I could work on a PR in a few days, let me know!

from nova-flexible-content.

wimurk avatar wimurk commented on July 23, 2024

+1 Is this already fixed? I have the same issue and can't remove any images.

from nova-flexible-content.

wimurk avatar wimurk commented on July 23, 2024

Any progress on this?

from nova-flexible-content.

element25 avatar element25 commented on July 23, 2024

I guess it's a complicated fix so does it make sense to update the docs to say that you can use a Trix field but not with images?

from nova-flexible-content.

rokde avatar rokde commented on July 23, 2024

Does anyone have a solution for bypassing this issue?

from nova-flexible-content.

wimurk avatar wimurk commented on July 23, 2024

@ajarti i tried so fix it myself but like you said the code is complex and hard to read.

i'm already looking for another package.

from nova-flexible-content.

voidgraphics avatar voidgraphics commented on July 23, 2024

@Nyratas Is there maybe a way we can also intercept this delete request in a middleware similar to what we have done for media library fields?

from nova-flexible-content.

toonvandenbos avatar toonvandenbos commented on July 23, 2024

@voidgraphics We could give it a try, but once again, that's a dirty workaround and I'm not sure we'll be able to fix it that way since it involves altering the behavior of an original Nova Controller.

For everyone's information, the file's delete route uses the resource's identifier and its field's attribute as parameters. This way, the controller will be able to find the file by resolving the field on the resource. If the file field is used inside a Flexible Content, the Nova Controller won't be able to find it (because it is not a root field of the resource) and returns an error. Believe me, this is not an easy issue.

@wimurk I agree, the code may sometimes be quite complex. Knowing it has multiple complex responsibilities in an environment that has not been built for its behavior, this may cause complex workarounds. However, it is not "hard to read" (in my opinion). Each method is documented, we use a clear naming convention, avoid method complexity as much as possible and do our best to implement SOLID principles wherever we can. I'm sure there's still room for enhancement, of course. Feel free to suggest code style changes if needed.

from nova-flexible-content.

slovenianGooner avatar slovenianGooner commented on July 23, 2024

So what I've tried to do was to flatten the array of available fields on DELETE requests - but then I have an issue because the query does not go through for updating in the database.

I somehow get over the "findFieldByAttribute" method by flattening the array of fields - but then it stops for me. If anyone can help I'd be happy to share my code and what I've done so far.

I don't even want to get started on nested flexible content etc.

from nova-flexible-content.

wimurk avatar wimurk commented on July 23, 2024

@slovenianGooner can you create a merge request so we can pull from that branch.

from nova-flexible-content.

slovenianGooner avatar slovenianGooner commented on July 23, 2024

@wimurk available at #72

from nova-flexible-content.

ibrahim-mubarak avatar ibrahim-mubarak commented on July 23, 2024

Any updates on this?

from nova-flexible-content.

paperscissors avatar paperscissors commented on July 23, 2024

it looks like these commits were launched in v0.2.6, but the problem persists.

from nova-flexible-content.

toonvandenbos avatar toonvandenbos commented on July 23, 2024

@paperscissors this problem exists since the beginning and there has not been an attempt to fix this since. Nova's file fields still need to be "root" fields for this to work, which is not the case when they're used inside Flexible fields.

from nova-flexible-content.

baskinvolkan avatar baskinvolkan commented on July 23, 2024

any update about the issue ?

from nova-flexible-content.

stuartcusackie avatar stuartcusackie commented on July 23, 2024

Just ran into this. Seems like no progress is being made.

If possible you can disable downloads and deletions. In my case this works fine but Nova really needs to sort out its fields system:

->deletable(false)
->disableDownload()

from nova-flexible-content.

dinmezpinar avatar dinmezpinar commented on July 23, 2024

Still persists

from nova-flexible-content.

SebastianBotez avatar SebastianBotez commented on July 23, 2024

Still persists

from nova-flexible-content.

LeonardoFraliniU2Y avatar LeonardoFraliniU2Y commented on July 23, 2024

Still persists

from nova-flexible-content.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.