diff --git a/admin/blocks.php b/admin/blocks.php
index b1c53df11f4..34e8e4e0e00 100644
--- a/admin/blocks.php
+++ b/admin/blocks.php
@@ -131,12 +131,25 @@
$table->setup();
$tablerows = array();
+ // Sort blocks using current locale.
+ $blocknames = array();
foreach ($blocks as $blockid=>$block) {
$blockname = $block->name;
+ if (file_exists("$CFG->dirroot/blocks/$blockname/block_$blockname.php")) {
+ $blocknames[$blockid] = get_string('pluginname', 'block_'.$blockname);
+ } else {
+ $blocknames[$blockid] = $blockname;
+ }
+ }
+ collatorlib::asort($blocknames);
+
+ foreach ($blocknames as $blockid=>$strblockname) {
+ $block = $blocks[$blockid];
+ $blockname = $block->name;
if (!file_exists("$CFG->dirroot/blocks/$blockname/block_$blockname.php")) {
$blockobject = false;
- $strblockname = ''.$blockname.' ('.get_string('missingfromdisk').')';
+ $strblockname = ''.$strblockname.' ('.get_string('missingfromdisk').')';
$plugin = new stdClass();
$plugin->version = $block->version;
@@ -151,7 +164,6 @@
$incompatible[] = $block;
continue;
}
- $strblockname = get_string('pluginname', 'block_'.$blockname);
}
$delete = ''.$strdelete.'';
@@ -222,12 +234,7 @@
$delete,
$settings
);
- $tablerows[] = array(strip_tags($strblockname), $row); // first element will be used for sorting
- }
-
- collatorlib::asort($tablerows);
- foreach ($tablerows as $row) {
- $table->add_data($row[1]);
+ $table->add_data($row);
}
$table->print_html();
diff --git a/lib/tests/textlib_test.php b/lib/tests/textlib_test.php
index 116f313c9a5..261cfddd7fc 100644
--- a/lib/tests/textlib_test.php
+++ b/lib/tests/textlib_test.php
@@ -471,6 +471,12 @@ class collatorlib_testcase extends basic_testcase {
$this->assertSame(array_keys($arr), array(0, 'b', 1));
$this->assertTrue($result);
+ // test sorting of array of arrays - first element should be used for actual comparison
+ $arr = array(0=>array('bb', 'z'), 1=>array('ab', 'a'), 2=>array('zz', 'x'));
+ $result = collatorlib::asort($arr, collatorlib::SORT_REGULAR);
+ $this->assertSame(array_keys($arr), array(1, 0, 2));
+ $this->assertTrue($result);
+
$arr = array('a' => 'áb', 'b' => 'ab', 1 => 'aa', 0=>'cc', 'x' => 'Áb',);
$result = collatorlib::asort($arr);
$this->assertSame(array_values($arr), array('aa', 'ab', 'áb', 'Áb', 'cc'), $this->error);
diff --git a/lib/textlib.class.php b/lib/textlib.class.php
index 540e4a4946a..77fafc1278e 100644
--- a/lib/textlib.class.php
+++ b/lib/textlib.class.php
@@ -616,7 +616,7 @@ class textlib {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class collatorlib {
- /** @const compare items as strings, equivalent to Collator::SORT_REGULAR */
+ /** @const compare items using general PHP comparison, equivalent to Collator::SORT_REGULAR, this may bot be locale aware! */
const SORT_REGULAR = 0;
/** @const compare items as strings, equivalent to Collator::SORT_STRING */