Ahh now I understand… I hope…
I know no other solution than the one mentioned by @metbril.
If I understand your needs correctly this time… then the following might be doing what you are after.
You might need some more regex to replace invalid chars like for example 's
.
Creating framework of plugin:
$ bin/plugin devtools newplugin
And replace most of old code and add the following:
public function onPluginsInitialized()
{
// Don't proceed if we are in the admin plugin
if (!$this->isAdmin()) {
return;
}
// Enable the main event we are interested in
$this->enable([
'onAdminSave' => ['onAdminSave', 0]
]);
}
public function onAdminSave(Event $e)
{
$page = $e['object'];
$slug = strtolower(preg_replace('/ /', '-', $page->title()));
$header = $page->header();
$header->slug = $slug;
$page->header($header);
}