Jump to content

Add user vs. PageName issue


KarlvonKarton
 Share

Recommended Posts

Hello there,

When I add a user and compare that with pageName, then I can see a difference with given $uniqueName.
 

$uniqueName= 'Prospère Jouplaboum';

$u = $users->add($uniqueName); // Results in name: prospe-ere-jouplaboum
/* VS. */
$username = $sanitizer->pageName(uniqueName); // Results in name: prospre-jouplaboum

 

ps: to correct the issue, I had to:

/* First pageName then add user... */
$uniqueName = $sanitizer->pageName($uniqueName);
$u = $users->add($uniqueName);

Strange, no?

Link to comment
Share on other sites

PagesEditor class uses $sanitizer->pageName() a bit differently.

// Users.php
add() -> PagesType::add()

// PagesType.php
public function ___add($name) {
	// ...
	$page->parent = $parent; 
	$page->name = $name; 
	// ...
	try {
		$this->save($page); 
	} 
	// ...
}

// PagesEditor.php
protected function savePageQuery(Page $page, array $options) {
	// ...
    if(strpos($page->name, $this->untitledPageName) === 0) $this->pages->setupPageName($page);

    $data = array(
        'parent_id' => (int) $page->parent_id,
        'templates_id' => (int) $page->template->id,
        'name' => $this->wire('sanitizer')->pageName($page->name, Sanitizer::toAscii),
        // ...
    );
	// ...
}

 

  • Like 1
Link to comment
Share on other sites

17 hours ago, KarlvonKarton said:

 


$uniqueName= 'Prospère Jouplaboum';

$u = $users->add($uniqueName); // Results in name: prospe-ere-jouplaboum
/* VS. */
$username = $sanitizer->pageName(uniqueName); // Results in name: prospre-jouplaboum

 

Hmmm, neither of those is a very good transliteration. $sanitizer->pageNameTranslate() gives the better result of prospere-jouplaboum, which is also the same result you get if you paste the name when adding a user via the PW admin. Seems like the core should be using that in PagesEditor instead of the Sanitizer::toAscii option.

  • Like 3
Link to comment
Share on other sites

In the meanwhile I've tested the pageName with option Sanitizer::toAscii, but that still results in the same differences.

So I'm sticking to this for now:

// adding
$saniName = $sanitizer->pageNameTranslate('Prospère Jouplaboum');
$u = $users->add($saniName);

// checking
$sane = $sanitizer->pageNameTranslate('Prospère Jouplaboum');
$exists = $pages->count("name=$sane") > 0;

 

  • Like 1
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...