I am using this hook to change uploaded file name to page title and site title + number of file. It looks to work well everywhere, but on frontpage, where I have banner as structure field, I am getting error, that file is not found. And itβs still uploaded with rightly renamed name. I can choose it later, but on upload I see empty file in structure img field.
'file.create:after' => function ($file) {
$kirby = $this;
$site = $this->site();
$page = $file->page();
$title = $page->title();
$st = $site->title();
$count = $page->files()->count() + 1;
$filename = $title . "-" . $st . "-" . $count - 1;
try {
$file->changeName($filename);
} catch(Exception $e) {
}
}