Mediafinder field attach to System\Models\File in component

Hello. I would like to inject image from media finder to my custom component.

fields.yaml

        cover:
            tab: example.example::lang.report.tab_manage
            label: example.example::lang.report.cover
            type: mediafinder
            mode: image
            maxItems: 1

Report.php model

[...]
    public $attachOne = [
        'cover' => ['System\Models\File'],
    ];

components/reports/card.htm component

[...]
{{ report.cover }}
[...]

component works but returns only part of url only /uploaded-files/authextimageresource1026windowsserver2012build8140.jpg

I would like it to return System\Models\File so I could do report.cover.getThumb(800, 480, {'mode': 'crop'}) OR at least full url /storage/app/media/uploaded-files/authextimageresource1026windowsserver2012build8140.jpg

Hi @jycoqav,

Doing {{ report.cover.path }} should give you the full path

It doesn’t because report.cover is a string, it means that it doesn’t attachOne cover to file. I’m using version build 476.

so in your case, you mixed up the cover field definition in your model.

if you want to use $attachOne, then you dont need to add a column to your model database.
if you want to use mediafinder, then you need to add a column to your model database that will hold the path string.

when using a mediafinder file, you can use {{ report.cover | media }}
when using a attachOne to a System\File, you can use {{ report.cover.path }}

in your example, you are trying to use both at the same time, and this would not work.
decide if you want to use mediafinder or an fileAttach first, then fix your code accordingly.

hope that helps

1 Like