Ok, now it works, thank you! I just wonder, is this not some sort of bug? Should it not be possible to use more than one update statement within one hook?
No, I need the filetype thing for all files, but I structured it in this way now:
[
'file.create:after' => function ($file) {
// change cover template to media, so images are also listed in the gallery
$filetype = $file->type();
if ($file->template() == 'cover') {
$file->update([
'template' => 'media',
'filetype' => $filetype
]);
} else {
if($filetype === 'video') {
try {
exec('ffmpeg -y -i ' . $file->root() . ' -ss 3 -t 1 ' . $file->parent()->root() . '/' . F::name($file->filename()) . '.jpg');
} catch(Exception $e) {
echo 'Video thumbnail could not be extracted.';
echo $e->getMessage();
}
}
$file->update(['filetype' => $filetype]);
}
}
]
However, when I update the template to media via the hook, it does change the template value in the meta file, but it does not write all the fields of the meta template to this file. I thought maybe I could place a $file->save() statement after the $file->update() to enforce this, but not only does this not work, this even makes the change of templates not work anymore. Is there any way to force updating all the fields in the meta file to the new template?
If I upload an image file to my gallery section (which uses the media template), the meta file gets auto-populated with all the templateās fields (most of them empty at this point in time).
Now, is there a way to auto-populate the image file that I upload in the cover field and then assign the media template to it with all the media template fields? (Example, why I need this: I have the Focus plugin installed which writes a field Focus: {"x":0.5,"y":0.5} during the auto-population, so it would be good to have such fields after I convert the template from cover to media).
Ah, yes, that was now a bit too obvious for me to see.
Ok, I think now I should have all my problems regarding this actually solved. This was a long one. Thank you so much for bearing with me, @texnixe. I canāt praise the Kirby support enough!