dmitrybubyakin / nova-medialibrary-field

Laravel Nova field for managing the Spatie media library
MIT License
264 stars 61 forks source link

Methods not working in Flexible content #118

Open martin-ro opened 3 years ago

martin-ro commented 3 years ago

Hi,

thanks for the great package!

I use Medialibrary fields within Flexible content but methods like resolveMediaUsing, downloadUsing, attachUsing etc. are not working at all. Seems like these methods are just ignored.

Example:

This works app\Nova\Page.php

Flexible :: make('Content')->addLayout(new MedialibraryFieldLayout('Media section', 'media-section', [
    Medialibrary::make('Media', 'media')->rules(['required'])
        ->downloadUsing(function (Media $media) {
            return 'xxxx';
        })
    ]))

This does not work app\Nova\Page.php

Flexible::make('Content')->addLayout(SomeCustomFlexibleLayout::class)->collapsed(true)

app\Nova\Flexible\Layouts\SomeCustomFlexibleLayout.php

...
public function fields()
    {
        return [
            Medialibrary::make('Media', 'media')->rules(['required'])
                ->downloadUsing(function (Media $media) {
                    return 'xxxx';
                })
        ]))

How can I get the methods working in custom layout classes?

Cheers

dmitrybubyakin commented 3 years ago

@martin-ro Hi! Could you please try extending this class https://github.com/dmitrybubyakin/nova-medialibrary-field/blob/master/src/Integrations/NovaFlexibleContent/MedialibraryFieldLayout.php?

martin-ro commented 3 years ago

Yeah, tried that before and the behavior seems to be the same.

dmitrybubyakin commented 3 years ago

@martin-ro Ok. I'll try to fix that over the weekend.

martin-ro commented 3 years ago

Hi @dmitrybubyakin, any news on that?

I'm still having trouble getting the Medialibrary field to work when using a flexible field with medialibrary within a flexible layout.

Field with attribute KDJNUhdxbakJ__logo is not found

martin-ro commented 3 years ago

Also just noticed that ->fields(function... doesn't work. Works when calling fields first before any other method

dmitrybubyakin commented 3 years ago

@martin-ro Hi. Still don't have time for this project