Kirby editor: How to get a file object of a block?

I’m trying out the new Kirby editor plugin and I’m struggling to get a file object of a block collection, in order to resize the stored images of each block and use them as a thumbnail.
Any advice?

<?php foreach($page->aside()->blocks()->filterBy('type', 'image') as $thumb): # List project-links ?>
    <?= $thumb->content()->toFile()->url() ?>
<?php endforeach ?>

What does $thumb return if you do a dump($thumb)?

Looks like it returns an ImageBlock object:

Kirby\Editor\ImageBlock Object
    [attrs:protected] => Kirby\Cms\Content Object
            [guid] => /pages/films/film-project/xyz.jpg
            [src] => http://localhost:8888/media/pages/films/film-project/xyz.jpg
            [id] => films/film-project/xyz.jpg
            [ratio] => 1.3461538461538
            [caption] => 
        ) …        

        [files] => Kirby\Cms\Files Object
                [0] => films/film-project/xyz-a.jpg
                [1] => films/film-project/xyz-b.jpg
                [2] => films/film-project/xyz-c.jpg
                [3] => films/film-project/xyz-d.jpg
            ) …

I have shortened the output and can also send you a message with the complete dump if you want.

Here we have a file Id we could use. The question is where the files array comes from.

Thanks @texnixe, I will take a different approach then and will create an additional image field in the blueprint to select a poster image.

<?php foreach($page->text()->blocks()->filterBy('type', 'image') as $block): # List project-links ?>
<?php dump($block->attrs()->id()->toFile()) ?>
<?php endforeach ?>

This gives you the file object

1 Like

Yes, this works :slightly_smiling_face: