block->imagesAsArraysWithCrops('image_set') gives objects with empty alt and caption

…even though those fields are filled up in Media library for those images. Edit: I was making some tests with blocks containing medias and there is no more medias at all after saving block with medias. I see saved images but in preview there is no $block->medias and $block->imagesAsArraysWithCrops('cover') returns empty array… Everything seems to be broken.
10 Replies
ifox
ifox5mo ago
You may be running into a regression we just found and fixed on 3.3. please downgrade to 3.2 or try this PR until the next release: https://github.com/area17/twill/pull/2625. These functions should work perfectly fine in previews
GitHub
Build software better, together
GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 420 million projects.
From An unknown user
From An unknown user
From An unknown user
Adam Mateusz Brożyński
For now I removed database, made migrations, created page, insterted my gallery block, add some images, save and medias in block is empty. If it's this regression problem shouldn't images load properly on fresh db? my block:
@twillBlockTitle(__('Gallery'))
@twillBlockIcon('b-image')
@twillBlockGroup('app')

<x-twill::medias
name="cover"
label="{{ __('Images') }}"
max="100"
/>
@twillBlockTitle(__('Gallery'))
@twillBlockIcon('b-image')
@twillBlockGroup('app')

<x-twill::medias
name="cover"
label="{{ __('Images') }}"
max="100"
/>
preview:
{{ var_dump($block->images('cover')) }}
{{ var_dump($block->images('cover')) }}
result:
array(0) {}
array(0) {}
But images are loaded. This happens also on fresh db. Its even weirder because after saving when I do {{dump($block)}} i see medias array there. But when I try to dump it by {{ dump($block->medias)}} then it's empty. I applied patches but no change. Ok this is strange. It started to work on freshdb only when I change medias form name to image and add to twill.php:
'default_crops' => [
'image' => [
'default' => [
[
'name' => 'default',
'ratio' => 4 / 3,
]
]
]
],
'default_crops' => [
'image' => [
'default' => [
[
'name' => 'default',
'ratio' => 4 / 3,
]
]
]
],
Any other name in form and duplicated in twill.php just won't work. I've cleared cache but nothing helps. Any ideas what is happening?
ifox
ifox5mo ago
each media field, if using a different name than image, should have a crop definition. In the model if it is a field outside a block, and inside the block or twill configuration if the media field is inside a block
Adam Mateusz Brożyński
I've tried two times on fresh database – the name has to be 'image' (and crop def) otherwise medias array is empty and cannot do $block->images('<name>'). Is is possible there's some kind of cache that optimize:clear and composer dump-autoload is not flushing? I had 'image' name at the very begining when I was creating first block with that name. Now I cannot use any other crop/field name because it's always empty. I've checked now on my working database – I cannot use any other crop and field name than 'image' if I want to have images.It is also in case of new blocks. Only 'image' crop and field nameworks and that's it. So am I defining it wrong in twill.php? I followed docs…
'default_crops' => [
'myimage' => [
'default' => [
[
'name' => 'default',
'ratio' => 4 / 3,
]
]
]
],
'default_crops' => [
'myimage' => [
'default' => [
[
'name' => 'default',
'ratio' => 4 / 3,
]
]
]
],
ifox
ifox5mo ago
where did you take default_crops from?
ifox
ifox5mo ago
This doesn't apply to blocks
Adam Mateusz Brożyński
Ok, thanks for link… I guess I defined it wrongly. I will check if it'll work. Now it works. Thanks. I thought it's global config for all props on website. 🙂
ifox
ifox5mo ago
I understand the possible confusion. This is a part of twill we still want to improve further. But once you get it, it is very powerful for art directed responsive imsges
Want results from more Discord servers?
Add your server