Sometimes I don’t want to bother generating slugs when creating/updating Pages. Idea is that the Slug would be the same value as Page UUID. My current solution:
^^ this removes the slug option when creating new page and prevents user to manualy changing slug afterwards
Page Model:
<?php
use Kirby\Uuid\Uuid;
class ProductPage extends Page
{
public static function create(array $props): Page
{
$uuid = Uuid::generate();
return parent::create(array_replace_recursive($props, [
'slug' => $uuid,
'content' => [
'uuid' => $uuid,
],
]));
}
}
This does the trick however is too much work and too much repeating and unnecessarily clutters the code when you want this feature for more types of pages. Wouldn’t it be nice to have this feature built in?
Yes, that was my first idea as well. However this creates different uuid values for slug and page uuid (stored within the content). Which is quite an odd behaviour, in my opinion.
What you could do is create a default page model with your create method, so if a page doesn’t need its own model, you save a lot of model creation. Other models can then simply extend this default model.