diff --git a/core/includes/common.inc b/core/includes/common.inc
index bffacfa..ae62741 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -5,6 +5,7 @@
 use Drupal\Component\Utility\Tags;
 use Drupal\Component\Utility\UrlValidator;
 use Drupal\Component\Utility\Xss;
+use Drupal\Component\Utility\SortArray;
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\Language\Language;
 use Symfony\Component\DependencyInjection\Container;
@@ -5180,14 +5181,22 @@ function element_info_property($type, $property_name, $default = NULL) {
  *   element, a default value of 0 will be used.
  * @param $b
  *   Second item for comparison.
+ *
+ * @see \Drupal\Component\Utility\String::checkPlain()
+ *
+ * @deprecated
  */
 function drupal_sort_weight($a, $b) {
-  $a_weight = (is_array($a) && isset($a['weight'])) ? $a['weight'] : 0;
-  $b_weight = (is_array($b) && isset($b['weight'])) ? $b['weight'] : 0;
-  if ($a_weight == $b_weight) {
-    return 0;
+  // Ensure we're passing an array to SortArray::sortWeight. If we didn't get an array in the
+  // first place then passing an empty array in will have the same effect as $a['weight'] will
+  // not be set.
+  if (!is_array($a)) {
+    $a = array();
   }
-  return ($a_weight < $b_weight) ? -1 : 1;
+  if (!is_array($b)) {
+    $b = array();
+  }
+  return SortArray::sortWeight($a, $b);
 }
 
 /**
diff --git a/core/lib/Drupal/Component/Utility/SortArray.php b/core/lib/Drupal/Component/Utility/SortArray.php
index e69de29..fbf6fe4 100644
--- a/core/lib/Drupal/Component/Utility/SortArray.php
+++ b/core/lib/Drupal/Component/Utility/SortArray.php
@@ -0,0 +1,41 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Component\Utility\SortArray.
+ */
+
+namespace Drupal\Component\Utility;
+
+/**
+ * Provides generic array sorting helper methods.
+ */
+class SortArray {
+
+  /**
+   * Sorts a structured array by the 'weight' element.
+   *
+   * Note that the sorting is by the 'weight' array element, not by the render
+   * element property '#weight'.
+   *
+   * Callback for uasort() used in various functions.
+   *
+   * @param array $a
+   *   First item for comparison. The compared items should be associative arrays
+   *   that optionally include a 'weight' element. For items without a 'weight'
+   *   element, a default value of 0 will be used.
+   * @param array $b
+   *   Second item for comparison.
+   *
+   * @return
+   *  The comparison result for uasort().
+   */
+  public static function sortWeight(array $a, array $b) {
+    $a_weight = isset($a['weight']) ? $a['weight'] : 0;
+    $b_weight = isset($b['weight']) ? $b['weight'] : 0;
+    if ($a_weight == $b_weight) {
+      return 0;
+    }
+    return ($a_weight < $b_weight) ? -1 : 1;
+  }
+}
diff --git a/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php b/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
index e69de29..75ed1b4 100644
--- a/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
@@ -0,0 +1,105 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Component\Utility\SortArrayTest.
+ */
+
+namespace Drupal\Tests\Component\Utility;
+
+use Drupal\Tests\UnitTestCase;
+use Drupal\Component\Utility\SortArray;
+
+/**
+ * Tests the MapArray system.
+ *
+ * @see \Drupal\Component\Utility\SortArray
+ */
+class SortArrayTest extends UnitTestCase {
+
+  public static function getInfo() {
+    return array(
+      'name' => 'SortArray test',
+      'description' => 'Test that the SortArray functions work properly.',
+      'group' => 'Common',
+    );
+  }
+
+  /**
+   * Tests SortArray::sortWeight() input against expected output.
+   *
+   * @dataProvider providerSortArray
+   *
+   * @param array $a
+   *   The first input array for the SortArray::sortWeight() method.
+   * @param array $b
+   *   The second input array for the SortArray::sortWeight().
+   * @param integer $expected
+   *   The expected output from calling the method.
+   *
+   * @see Drupal\Component\Utility\SortArray::sortWeight()
+   * @see Drupal\Tests\Component\Utility\SortArrayTest::providerSortArray()
+   */
+  public function testSortArray($a, $b, $expected) {
+    $result = SortArray::sortWeight($a, $b);
+    $this->assertEquals($expected, $result);
+  }
+
+  /**
+   * Data provider for SortArray::sortWeight().
+   *
+   * @return array
+   *   An array of tests, matching the parameter inputs for testSortArray.
+   *
+   * @see Drupal\Component\Utility\SortArray::sortWeight()
+   * @see Drupal\Tests\Component\Utility\SortArrayTest::testSortArray()
+   */
+  public function providerSortArray() {
+    $tests = array();
+
+    // Weights set and equal
+    $tests[] = array(
+      array('weight' => 1),
+      array('weight' => 1),
+      0
+    );
+
+    // Weights set and $a is less (lighter) than $b
+    $tests[] = array(
+      array('weight' => 1),
+      array('weight' => 2),
+      -1
+    );
+
+    // Weights set and $a is greater (heavier) than $b
+    $tests[] = array(
+      array('weight' => 2),
+      array('weight' => 1),
+      1
+    );
+
+    // Weights not set
+    $tests[] = array(
+      array(),
+      array(),
+      0
+    );
+
+    // Weights for $b not set
+    $tests[] = array(
+      array('weight' => 1),
+      array(),
+      1
+    );
+
+    // Weights for $a not set
+    $tests[] = array(
+      array(),
+      array('weight' => 1),
+      -1
+    );
+
+    return $tests;
+  }
+
+}
