diff --git a/core/includes/common.inc b/core/includes/common.inc index bf82ba3..ca270df 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1753,8 +1753,8 @@ function drupal_exit() { * * @see \Drupal\Component\Utility\MapArray::copyValuesToKeys() */ -function drupal_map_assoc($array, $callback = NULL) { - return MapArray::copyValuesToKeys($array, $callback); +function drupal_map_assoc($array, $callable = NULL) { + return MapArray::copyValuesToKeys($array, $callable); } /** diff --git a/core/lib/Drupal/Component/Utility/MapArray.php b/core/lib/Drupal/Component/Utility/MapArray.php index f671223..6c00dcd 100644 --- a/core/lib/Drupal/Component/Utility/MapArray.php +++ b/core/lib/Drupal/Component/Utility/MapArray.php @@ -29,13 +29,16 @@ class MapArray { * @return array * An associative array. */ - public static function copyValuesToKeys(array $array, $callback = NULL) { + public static function copyValuesToKeys(array $array, $callable = NULL) { // array_combine() fails with empty arrays: // http://bugs.php.net/bug.php?id=34857. - $array = !empty($array) ? array_combine($array, $array) : array(); - if (is_callable($callback)) { - $array = array_map($callback, $array); + if (!empty($array)) { + $array = array_combine($array, $array); } + if (is_callable($callable)) { + $array = array_map($callable, $array); + } + return $array; } diff --git a/core/tests/Drupal/Tests/Component/Utility/MapArrayTest.php b/core/tests/Drupal/Tests/Component/Utility/MapArrayTest.php index 13d984b..c5e7c12 100644 --- a/core/tests/Drupal/Tests/Component/Utility/MapArrayTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/MapArrayTest.php @@ -34,14 +34,14 @@ public static function getInfo() { * The input variable for the MapArray::copyValuesToKey() function. * @param $expected * The expected output from when calling the function. - * @param callable $function - * The optional function callback. + * @param callable $callable + * The optional callable. * * @see Drupal\Component\Utility\MapArray::copyValuesToKey() * @see Drupal\Tests\Component\Utility\MapArrayTest::providerCopyValuesToKey() */ - public function testCopyValuesToKey($input, $expected, $function = NULL) { - $output = MapArray::copyValuesToKeys($input, $function); + public function testCopyValuesToKey($input, $expected, $callable = NULL) { + $output = MapArray::copyValuesToKeys($input, $callable); $this->assertEquals($expected, $output); } @@ -95,7 +95,7 @@ public function providerCopyValuesToKey() { * @param $n * The value passed in from array_map(). */ - public function providerCopyValuesToKeyCallback($n) { + public static function providerCopyValuesToKeyCallback($n) { return $n * 2; }