diff --git a/core/lib/Drupal/Component/Utility/NestedArray.php b/core/lib/Drupal/Component/Utility/NestedArray.php
index 8e00e06..32abd05 100644
--- a/core/lib/Drupal/Component/Utility/NestedArray.php
+++ b/core/lib/Drupal/Component/Utility/NestedArray.php
@@ -344,4 +344,43 @@ public static function mergeDeepArray(array $arrays, $preserve_integer_keys = FA
     return $result;
   }
 
+  /**
+   * Inserts values into an array after a given key.
+   *
+   * Values from $insert_array are inserted after (or before) $key in $array. If
+   * $key is not found, $insert_array is appended to $array using array_merge().
+   *
+   * @param array $array
+   *   The array to insert into. Passed by reference and altered in place.
+   * @param mixed $key
+   *   The key of $array to insert after
+   * @param array $insert_array
+   *   An array whose values should be inserted.
+   * @param bool $before
+   *   If TRUE, insert before the given key, rather than after it.
+   *   Defaults to inserting after.
+   */
+  public static function insert(&$array, $key, $insert_array, $before = FALSE) {
+    $done = FALSE;
+    foreach ($array as $array_key => $array_val) {
+      if (!$before) {
+        $new_array[$array_key] = $array_val;
+      }
+      if (!$done && ($array_key == $key)) {
+        foreach ($insert_array as $insert_array_key => $insert_array_val) {
+          $new_array[$insert_array_key] = $insert_array_val;
+        }
+        $done = TRUE;
+      }
+      if ($before) {
+        $new_array[$array_key] = $array_val;
+      }
+    }
+    if (!$done) {
+      $new_array = array_merge($array, $insert_array);
+    }
+    // Put the new array in the place of the original.
+    $array = $new_array;
+  }
+
 }
diff --git a/core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php b/core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php
index 08c9f78..a2f2f31 100644
--- a/core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php
@@ -185,6 +185,65 @@ public function testMergeDeepArray() {
   }
 
   /**
+   * Tests \Drupal\Component\Utility\NestedArray::insert().
+   */
+  public function testInsert() {
+    // Test that we can insert an item in between other items in an array.
+    $array = array(
+      'first' => 'first item',
+      'third' => 'third item',
+    );
+
+    $second = array(
+      'second' => 'second item',
+    );
+
+    NestedArray::insert($array, 'first', $second);
+
+    $expectedArray = array(
+      'first' => 'first item',
+      'second' => 'second item',
+      'third' => 'third item',
+    );
+
+    $this->verifyArrayOrder($array, $expectedArray);
+
+    // Test that we can properly insert an item to the end of an array.
+    $last = array(
+      'last' => 'last item',
+    );
+
+    NestedArray::insert($array, 'third', $last);
+    $expectedArray['last'] = 'last item';
+    $this->verifyArrayOrder($array, $expectedArray);
+
+    // Test that we can properly insert an item to the beginning of an array.
+    $zero = array(
+      'zero' => 'zero item',
+    );
+
+    NestedArray::insert($array, 'first', $zero, TRUE);
+    array_unshift($expectedArray, 'zero item');
+    $this->verifyArrayOrder($array, $expectedArray);
+  }
+
+  /**
+   * Verify that two arrays contain identical items in the same order.
+   *
+   * @param array $array
+   *   The array of values to test.
+   * @param array $expectedArray
+   *   The array of values that should exist in $array to assert against.
+   */
+  protected function verifyArrayOrder($array, $expectedArray) {
+    reset($array);
+    foreach ($expectedArray as $expectedValue) {
+      $this->assertEquals(current($array), $expectedValue, 'Arrays contain identical values.');
+      next($array);
+    }
+  }
+
+  /**
    * Tests that arrays with implicit keys are appended, not merged.
    *
    * @covers ::mergeDeepArray
