Search the Community
Showing results for tags 'prepend'.
-
Hey Procis, wrote this - and my very first - hook „Prepend date in page name“, yesterday. Once you get it, this system and the API is magnificent. Thank you @ryan and @all contributers! On new (news) pages it works great so far. E.g.: Title: Testnews mit Ümläüten Altered page name: 2024-09-24-testnews-mit-ümläüten But on existing pages special characters are removed. E.g. Title: Partnerschaftliche Unterstützung - Ihr werdet gesucht! Altered page name: 2023-07-27-fans1991-partnerschaftliche-untersttzung-ihr-werdet-gesucht Another example is attached. There you can see, that the ProcessPageEdit-message shows the right path!? I have this in my site/config.php to allow only german special characters: $config->pageNameCharset = 'UTF8'; $config->pageNameWhitelist = '-_abcdefghijklmnopqrstuvwxyz0123456789äöüß'; Temporary uninstalled Module „PagePathHistory“ with no look. The code of my hook (suggestions for improvement are very welcome!): /* NEWS pages only: prepend date in page-name */ $wire->addHookAfter('Pages::saveReady', function($event) { // get current Page object — in this case this is the first argument for the $event object $page = $event->arguments(0); // Only for pages with news template if($page->template == 'news') { // Test if field day exists, otherwise exit if (!$page->template->hasField('day')) { $event->message("Field 'day' is missing!"); return; } $title = $page->get('title'); // Sanitize title and substitute special characters $optimizedTitle = wire('sanitizer')->pageNameUTF8($title); //$optimizedTitle = wire('sanitizer')->pageName($title, Sanitizer::okUTF8); // or translate option $date = wireDate('Y-m-d', $page->day); // Set output formatting state off, for page manipulation $page->of(false); $page->name = $date.'-'.$optimizedTitle; //$page->save('name'); $event->message("New saved name is $page->name"); //$event->message("Path of new saved page is $page->path"); } }); Any idea why this doesn't works on all existing news, too? Thx and 👋 Sebastian