No Image Content Informations on Virtual Page

I’ve got Virtual Pages which are generated for every User with the role Artist. I’ve just added this line in the artists model:

'files'    => $artist ? $artist->files()->toArray() : null,

The Problem is, that the FocusCrop Plugin doesn’t work anymore. On the Page the image src is: “(https://www.siriusstudios.at/media/pages/artists/samuel-leeb/ffd42c9be1-1696189247/img-1215-500x600-crop-72-50.jpg) ”. But there is no cropped image in my folder. I’ve just got an .json file:
image

I’ve just dumped the image:

<?=dump($image)?>

I found out, that the content, where the focus informations are normally saved is empty on the virtual page:

[template] => gallery
[content] => Kirby\Cms\Content Object
(
)

But on the old Artist Pages, where the file was saved in the content folder it looked like this:

[template] => gallery
[content] => Kirby\Cms\Content Object
(
[focus] => {"x":0.4,"y":0.46}
[sort] => 4
[uuid] => ShSnYALzINeuhgsb
[template] => gallery
)

My theory is, that this code:

'files'    => $artist ? $artist->files()->toArray() : null,

overwrites the image informations…

Where did you add this? In the content array? To get the files of an artists as files of the virtual page, you need to overwrite the $page->files() method in your model, so that it fetches the files from the corresponding user.

I’ve got following code in the models/artists.php:

 <?php

use Kirby\Uuid\Uuid;

class ArtistsPage extends Kirby\Cms\Page
{
    public function children(): Pages
    {
        if ($this->children instanceof Pages) {
            return $this->children;
        }

        $artists = [];

        foreach (kirby()->users()->filterBy('role','artist') as $artist) {
            $artists[] = [
                'slug'     => strtolower(str_replace(' ', '-', $artist->name())),
                'num'      => 0,
                'template' => 'artist',
                'model'    => 'artist',
                 //Here's the files Code!
                'files'    => $artist ? $artist->files()->toArray() : null,
                'content'  => [
                    'text'  => $artist->name(),
                    'user'  => $artist->name(),
                    'since' => $artist->since(),
                    'tags' => $artist->tags(),
                    'description' => $artist->description(),
                    'uuid'  => Uuid::generate(),
                ]
            ];
        }

        return $this->children = Pages::factory($artists, $this);
    }
}

How do I overwrite the $page->files() method in my model?

With the help of flokosiol we figured it out!
We deleted the "files to Array" line and changed the content in the model like this:

foreach (kirby()->users()->filterBy('role','editor') as $artist) {
            $artists[] = [
                'slug'     => strtolower(str_replace(' ', '-', $artist->name())),
                'num'      => 0,
                'template' => 'artist',
                'model'    => 'artist',
                'content'  => [
                    'gallery' => $artist->images()->filterBy('template', 'gallery'),
                    'text'  => $artist->name(),
                    'user'  => $artist->name(),
                    'since' => $artist->since(),
                    'tags' => $artist->tags(),
                    'description' => $artist->description(),
                ]
            ];
        }

To use the image with the focus Plugin you just have to write this code into the template:

<?php if ($page->gallery()->isNotEmpty()): ?>
  <?php foreach ($page->gallery()->value() as $image): ?>
      <?= $image->focusCrop(200, 200) ?>
  <?php endforeach; ?>
<?php endif; ?>