Mediafinder in theme.yaml with maxItems: 0 not working in october 3

Hi.

If I use mediafinder in theme.yaml like this:

form:
    tabs:  
        fields:  
            workings:
                label: 'Working for'
                tab: 'Working for'
                type: mediafinder
                maxItems: 0
                mode: image

When I tried to save the data I’ve got this error:

"Unexpected type of array when attempting to save attribute "workings", try adding it to the $jsonable property." on line 387 of /Users/martinpolak/Sites/nerd/vendor/october/rain/src/Database/Model.php

Doesnt work in filesystem mode nor database mode.

I gotta ask, what’s your use case for this?

Its for the logos in the footer.

Since 0 isn’t a valid entry for that, what I would do is this:

  • Set the maxItems to 1
  • In your template, write some code to only show it if it’s there:
{% if footer_image|length %}
  {{ footer_image|media }}
{% endif %}

I may be understanding wrong tho. If you plan to have unlimited images, just delete the maxItems property

Man, its a bug.
Please, I dont need only one item, maxItems with 0 is a valid entry - check here:
https://octobercms.com/forum/post/mediafinder-in-themeyaml-doesnt-support-multiple-files

So I need to fix this bug.

1 Like

I think it’s a bug indeed, because only repeaters and nestedforms are currently added as jsonable attributtes automatically. But there is a workaround. Try this:

form:
    tabs:
        fields:
            workings[images]:
                label: 'Working for'
                tab: 'Working for'
                type: mediafinder
                maxItems: 0
                mode: image

And in your template:

{% for image in this.theme.workings.images %}
    <img src="{{ image | media }}">
{% endfor %}
3 Likes

Apologies, just trying to help. Glad you were able to find a solution.

2 Likes

To use the mediafinder which is able to add multiple images, you need to add the property as $jsonable to your model like this:
protected $jsonable = ['workings'];

This is indeed a bug and will be fixed in the next release (v3.0.62+). The workaround by @acasar is also a good solution in the meantime.

2 Likes

I know, but this isn’t a plugin model, its a theme model.

1 Like