gebeer Posted November 10, 2015 Posted November 10, 2015 Hello, I have a multilanguage page, running on PW 2.6.23. This is a conversion of a german Joomla site which already has active members. It is a requirement to have a specific format for user names which are generated from the Full Name of a user: "Test Üser" should become "Test_Ueser_1552", where 1552 is the user id. (note conversion of Umlaut Ü to Ue) I have changed and added Umlaut conversion in the InputfieldPageName settings to read: æ=ae å=a ä=ae Ä=ae ß=ss ö=oe Ö=oe ü=ue Ü=ue ... I have created a "member" template based on the user template, following instructions here. This is all working fine and I can create member users. My member template has a text field "fullname". Now I have written a small module to create my custom user name format from the fullname field: public function init() { $this->pages->addHookBefore('Pages::saveReady', $this, 'renameMember'); } protected function renameMember($event) { $page = $event->arguments[0]; if($page->template != 'member') return; $sanitizer = wire('sanitizer'); if($page->isChanged('fullname') && !empty($page->fullname)) { $name = $page->fullname; $newName = str_replace(" ", "_", $name) . "_" . $page->id; $newNameSave = $sanitizer->pageName($newName, "Sanitizer::translate"); $page->name = $newNameSave; $message = __("Benutzername wurde angepasst: ") . $newNameSave ; $this->message($message); } } But every time I try this, "Test Üser" becomes "test_ser_1552". The same goes for "Test üser". If I try "Test Güser", I get "test_g-ser_1552". So ü gets replaed by a dash -. When I create regular pages (e.g. basic-page template) the conversion of Ü and ü to ue for the page name is working just fine. Could there be a problem with using $sanitizer->pageName($newName, "Sanitizer::translate"); inside a module? Or is the username field treated differently from the page name field? Any solution would be much appreciated.
LostKobrakai Posted November 10, 2015 Posted November 10, 2015 To clarify Soma's answer a bit: $newNameSave = $sanitizer->pageName($newName, Sanitizer::translate); It's a class constant not a string. 1
gebeer Posted November 10, 2015 Author Posted November 10, 2015 Thank you @Soma and @LostKobrakai That did the trick Got confused by the cheatsheet saying: If second parameter is "Sanitizer::translate" it will use the language char conversion defined in InputfieldPageName module settings.
Soma Posted November 10, 2015 Posted November 10, 2015 Or use new $sanitizer->pageNameTranslate(str) 2
gebeer Posted November 10, 2015 Author Posted November 10, 2015 Or use new $sanitizer->pageNameTranslate(str) Thanks for this one. Shorter is better
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now