I’ve been trying to get the hook to work for ages but I keep getting error messages. I know that Kirby objects are immutable but I can’t find a solution that works. Does anyone know what I’m doing wrong and how I should deal with the immutable objects? I have already cached them in variables but somehow something is missing … (Plugin for AddFields is active)
'page.create:after' => function ($page, $input) {
if ( $page->intendedTemplate() == 'patient' ) {
$kirby = kirby();
try {
$page->createChild([
'slug' => 'nachrichten',
'template' => 'nachrichten',
'draft' => false,
'content' => [
'title' => 'Nachrichten'
]
]);
} catch (Exception $e) {
echo $e->getMessage();
}
try {
$page->update([
'vorname' => $page->vorname(),
'nachname' => $page->nachname()
]);
} catch(Exception $e) {
echo $e->getMessage();
}
$title = $page->nachname() . ' ' . $page->vorname();
$slug = bin2hex(random_bytes(25));
$new = $page->changeTitle($title);
$new->changeSlug($slug);
}
}