Repeaters and Blockeditor won't work with media library.
I saw the pst regarding JSON repeaters. So I switched to the block editor for the content that NEEDS some kind of a repeater.
How can I achieve this? What should I upgrade or how can I integrate this repeatable medias feature? In our design, there are lots of blocks that needs this.
36 Replies
I'm not sure what you mean @Hazarcan Doğa, you can create blocks that include repeater fields, in which you can use medias fields
Repeaters and blocks perfectly work with the media library. only JSON repeaters don't
Repeaters outside of blocks also work with the media library, as long as you are storing the repeated item in a dedicated model, with a hasMany relationship, instead of storing everything in a JSON column (which in most cases is not a great idea)
I am not sure that I fully grasp the difference between the JSON repeaters and normal repeaters.
from a form standpoint they are the same, the difference is where you save it
with json repeaters, you save it in a column of your model
with a normal repeater you saive it in a separate model
For example I think "InlineRepeater" is the json repeater. In which case it doesn't work because fields are saved as a JSON instead of a blockable releationship
with a foreign key
like I said, form is the same for both
oh you're in a block???
repeaters in blocks are just children blocks
However, this is a block I created, if I use it it will work with media. However when I call it inside a "BlockEditor" form field, again the media relations won't work am IO correct
Yes
I am trying to integrate this block with a repeater of media, browser and multiple text fields.
And there are many more structures where I need media inside a repeater, all related to blocks of course. So it is crucial for me to find a work around about this. I need to use medias with repeaters inside blocks. I read the documentation maybe I missed something.
there is no work around needed to do this. what exactly is not working? did you set a crop configuration for your medias field named
bg
?What do you mean by repeaters here? the first example in this page? https://twillcms.com/docs/form-fields/repeater.html
Of course the issue is, when I use the block like this in BlockEditor FormField
These are my crops
You need a ratio in those crops
If you don't want to force any ratio, use 0 or null
@ifox I was mistaken, When I used BlockEditor form field and separated the repeater conten into an another block, medias worked fine. However, eventhough I added to ratios to the crops as you suggested, In the editor page, media fields are fetched empty eventhough I know I filled the fields before saving and refreshing the page. The video shows what I mean.
What's the name of your nested blocks medias field?
ha variable_image I guess
and it renders on your frontend, I see, so it actually saves correctly
I'll try to reproduce
Yes, it does. The first component is a nested block, second one is normal as you can see, both have the same problem.
Can you please share the 2 block classes?
also, which version of Twill are you on?
I was in my lunch break yes sure
This is the first block
Second block (developed in twill 2.0)
"version": "3.x-dev",
additionally page module class
In the form for Page, what do you have?
This is what I have
@ifox do you think that using a blade in the module and formBuilder in blocks would couse this?
it should not
That shouldn't normally be an issue but try naming variable_image inside one of the 2 blocks differently (and a new crop key in config accordingly)
I changed one and removed the other block from the page, still the same issue.
This is the output of "$this->form($id)" in edit() method of A17\Twill\Http\Controllers\Admin\ModuleController
I think I got it
You're using translated medias fields?
And/or changed the main locale of your application?
Data seems to be like that but normally no I don't use medias to be translated
Let me check
I see
tr
in the medias keysyes you are correct the system language is in turkish
However I don't use translated() option in media fields
let me check one thing
Check twill.media_library config
It's enabled globally
Yes that was the cause... Thank you very much.
One more question, what if I'd use a repeater with a blade template on it's own... would media worked the same way it worked in BlockEditor?
yes