Jump to content

Admin Data Table and rows starting with numbers cause problems


teppo
 Share

Recommended Posts

For some reason Admin Data Table breaks when you insert a row which starts with number. See attached screenshot -- link doesn't show up and instead it's URL is printed out as plain text. Screenshot is from (unmodified) admin/users, but I'm seeing same strange behavior when adding rows to custom made Admin Data Table too.

So far I've tested this with 2.1 and 2.2 and I'm seeing same bug in both.

Can anyone else produce this or is there something wrong with my PW installation(s)?

post-175-0-77362200-1337670749_thumb.png

Link to comment
Share on other sites

I can't reproduce this. Works all as it should.

But I think you're missing the "setEncodeEntities" setting.

$dt = $this->modules->get("MarkupAdminDataTable");
$dt->setEncodeEntities(false);
...
Link to comment
Share on other sites

@soma, actually I failed to explain this properly. It's not enough that name starts with a number, it must BE a number.

As far as I can see, this seems to be caused by function "row" of MarkupAdminDataTable.module, more specificly this check:

if(is_string($k)) {
	// Associative arrays get converted to:
	// Anchor Text => URL
	$v = "<a href='$v'>" . $this->encode($k) . "</a>";
} else {
	$v = $this->encode($v);
}

So unless I'm missing something, 123 (username in this test) isn't a string (is_string($k) === false) and because of that link isn't created (and name is dumped.) Right? :)

Link to comment
Share on other sites

Ah, sorry I didn't get it that's on user list.

You're right, user names with only numbers breaks the output.

In DataTable, if a row array entry is a key=value, where value would be a url, it will be outputed as link automaticly...

$row["username"] = "edit/?=123";

This is the code that does it on user list in ProcessPageType.module :

foreach($fieldNames as $name) {
   if(!$n) $row[(string)$page->get($name)] = "edit/?id={$page->id}";
       else $row[] = $this->renderListFieldValue($name, $page->get($name)); 
   $n++;
}

So you're right. Even though the key should be a (string) it doesn't work with a number.

Link to comment
Share on other sites

Despite that number being typecast to a string, it looks like PHP actually typecasts it back to an integer if the string contains only digits, when creating an array index. I found that I could get PHP to keep it as a string if I appended a non-digit character to the end of it (space). I just committed the update, so this issue should be fixed. Since this PHP typecasting behavior is a little unexpected, I'm just hoping the behavior is the same across PHP versions. Let me know if you find there is still an issue.

  • Like 2
Link to comment
Share on other sites

  • 2 years later...

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...