Jump to content

Umlauts not transcribed correctly in custom user name module


gebeer
 Share

Recommended Posts

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. 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...