diff --git a/core/includes/common.inc b/core/includes/common.inc index 3c03eb71c854153a883c5142d79b4b6ee20d387f..6a2ac0788d8a4c439a9a28411b723be3589cb827 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -16,7 +16,6 @@ use Symfony\Component\Yaml\Parser; use Symfony\Component\Yaml\Exception\ParseException; use Drupal\Component\PhpStorage\PhpStorageFactory; -use Drupal\Component\Utility\MapArray; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Routing\GeneratorNotInitializedException; @@ -1290,15 +1289,6 @@ function l($text, $path, array $options = array()) { return '<a href="' . $url . '"' . $attributes . '>' . $text . '</a>'; } -/** - * Forms an associative array from a linear array. - * - * @see \Drupal\Component\Utility\MapArray::copyValuesToKeys() - */ -function drupal_map_assoc($array, $callable = NULL) { - return MapArray::copyValuesToKeys($array, $callable); -} - /** * Attempts to set the PHP maximum execution time. * diff --git a/core/includes/form.inc b/core/includes/form.inc index 8636c1a1fb64c588a7c589e1ae0d8e56c288466a..62e8f9a5374ba78513666548d53e690fd06f1e0b 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -559,7 +559,7 @@ function form_type_checkboxes_value($element, $input = FALSE) { unset($input[$key]); } } - return drupal_map_assoc($input); + return array_combine($input, $input); } else { return array(); @@ -588,10 +588,11 @@ function form_type_table_value(array $element, $input = FALSE) { // @todo D8: Remove this inconsistency. if ($input === FALSE) { $element += array('#default_value' => array()); - return drupal_map_assoc(array_keys(array_filter($element['#default_value']))); + $value = array_keys(array_filter($element['#default_value'])); + return array_combine($value, $value); } else { - return is_array($input) ? drupal_map_assoc($input) : array(); + return is_array($input) ? array_combine($input, $input) : array(); } } } @@ -666,7 +667,7 @@ function form_type_tableselect_value($element, $input = FALSE) { return $value; } else { - return is_array($input) ? drupal_map_assoc($input) : array(); + return is_array($input) ? array_combine($input, $input) : array(); } } } @@ -711,7 +712,7 @@ function form_type_select_value($element, $input = FALSE) { // unselected. A disabled multi-select always submits NULL, and the // default value should be used. if (empty($element['#disabled'])) { - return (is_array($input)) ? drupal_map_assoc($input) : array(); + return (is_array($input)) ? array_combine($input, $input) : array(); } else { return (isset($element['#default_value']) && is_array($element['#default_value'])) ? $element['#default_value'] : array(); diff --git a/core/includes/theme.inc b/core/includes/theme.inc index dad6f65bd625812dbdb1521b38253ed919941575..5064d6eee9e1c713e95d20ee68888c2cdaf18100 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -17,7 +17,6 @@ use Drupal\Core\Template\RenderWrapper; use Drupal\Core\Theme\ThemeSettings; use Drupal\Component\Utility\NestedArray; -use Drupal\Component\Utility\MapArray; use Drupal\Core\Render\Element; /** @@ -1291,10 +1290,11 @@ function template_preprocess_links(&$variables) { // Use the array key as class name. $li_attributes['class'][] = drupal_html_class($key); + $keys = array('title', 'href', 'route_name', 'route_parameters'); $link_element = array( '#type' => 'link', '#title' => $link['title'], - '#options' => array_diff_key($link, MapArray::copyValuesToKeys(array('title', 'href', 'route_name', 'route_parameters'))), + '#options' => array_diff_key($link, array_combine($keys, $keys)), '#href' => $link['href'], '#route_name' => $link['route_name'], '#route_parameters' => $link['route_parameters'], diff --git a/core/includes/update.inc b/core/includes/update.inc index 3431886e473ca957022c19e4a44676c66e5df344..5700d385ec82b4861cdd3fa2dfbe0389be17aa64 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -434,7 +434,7 @@ function update_get_update_list() { continue; } - $updates = drupal_map_assoc($updates); + $updates = array_combine($updates, $updates); foreach (array_keys($updates) as $update) { if ($update == \Drupal::CORE_MINIMUM_SCHEMA_VERSION) { $ret[$module]['warning'] = '<em>' . $module . '</em> module cannot be updated. It contains an update numbered as ' . \Drupal::CORE_MINIMUM_SCHEMA_VERSION . ' which is reserved for the earliest installation of a module in Drupal ' . \Drupal::CORE_COMPATIBILITY . ', before any updates. In order to update <em>' . $module . '</em> module, you will need to install a version of the module with valid updates.'; diff --git a/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php b/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php index ba87dfb59202d4f81b92c92a664e4b0f2d66194f..48a860feae41f7dff24d8bf1697de054188242cb 100644 --- a/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php +++ b/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php @@ -8,7 +8,6 @@ namespace Drupal\Component\Plugin; use Drupal\Component\Plugin\Exception\PluginNotFoundException; -use Drupal\Component\Utility\MapArray; /** * Provides a default plugin bag for a plugin type. @@ -63,7 +62,8 @@ public function __construct(PluginManagerInterface $manager, array $configuratio $this->configurations = $configurations; if (!empty($configurations)) { - $this->instanceIDs = MapArray::copyValuesToKeys(array_keys($configurations)); + $instance_ids = array_keys($configurations); + $this->instanceIDs = array_combine($instance_ids, $instance_ids); // Store the original order of the instance IDs for export. $this->originalOrder = $this->instanceIDs; } diff --git a/core/lib/Drupal/Component/Utility/MapArray.php b/core/lib/Drupal/Component/Utility/MapArray.php deleted file mode 100644 index ea91e63ff2d75c1532d53c4e7a9deb3eb7a949e4..0000000000000000000000000000000000000000 --- a/core/lib/Drupal/Component/Utility/MapArray.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\Component\Utility\MapArray. - */ - -namespace Drupal\Component\Utility; - -/** - * Provides generic array mapping helper methods. - */ -class MapArray { - - /** - * Forms an associative array from a linear array. - * - * This function walks through the provided array and constructs an associative - * array out of it. The keys of the resulting array will be the values of the - * input array. The values will be the same as the keys unless a function is - * specified, in which case the output of the function is used for the values - * instead. - * - * @param array $array - * A linear array. - * @param callable $callback - * A name of a function to apply to all values before output. - * - * @return array - * An associative array. - */ - public static function copyValuesToKeys(array $array, $callable = NULL) { - // array_combine() fails with empty arrays: - // http://bugs.php.net/bug.php?id=34857. - if (!empty($array)) { - $array = array_combine($array, $array); - } - if (is_callable($callable)) { - $array = array_map($callable, $array); - } - - return $array; - } - -} diff --git a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php index 13f0388c6a12fb854acfc6ceccbf026c9549cd24..222145f99aa8c069328b2a7c84781b70b6e03cd4 100644 --- a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php @@ -410,7 +410,8 @@ protected function buildQuery($ids, $revision_id = FALSE) { if ($this->revisionTable) { // Add all fields from the {entity_revision} table. - $entity_revision_fields = drupal_map_assoc(drupal_schema_fields_sql($this->entityType->getRevisionTable())); + $entity_revision_fields = drupal_schema_fields_sql($this->entityType->getRevisionTable()); + $entity_revision_fields = array_combine($entity_revision_fields, $entity_revision_fields); // The ID field is provided by entity, so remove it. unset($entity_revision_fields[$this->idKey]); diff --git a/core/lib/Drupal/Core/Utility/ProjectInfo.php b/core/lib/Drupal/Core/Utility/ProjectInfo.php index 748470ccfb9f4d1ad6c44873b26563d1cd61b187..0b5090ec21234b4db4b3931c6bb07387cf3c2e36 100644 --- a/core/lib/Drupal/Core/Utility/ProjectInfo.php +++ b/core/lib/Drupal/Core/Utility/ProjectInfo.php @@ -224,7 +224,7 @@ function filterProjectInfo($info, $additional_whitelist = array()) { 'version', ); $whitelist = array_merge($whitelist, $additional_whitelist); - return array_intersect_key($info, drupal_map_assoc($whitelist)); + return array_intersect_key($info, array_combine($whitelist, $whitelist)); } } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php b/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php index 469b1944e1f20d1acec731d681353cf1deedef0f..2edb0f012a2691667e1cce251ccd4eb1633bd4b2 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php @@ -23,7 +23,8 @@ class FeedFormController extends ContentEntityFormController { */ public function form(array $form, array &$form_state) { $feed = $this->entity; - $period = drupal_map_assoc(array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval'); + $intervals = array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200); + $period = array_map('format_interval', array_combine($intervals, $intervals)); $period[AGGREGATOR_CLEAR_NEVER] = $this->t('Never'); $form['title'] = array( diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php index b370063022f07e8ed3dc1a1b93f9fb3c9f338119..e80c9b1bf43df4cb6d5f871907299613ff6da62c 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php @@ -80,8 +80,8 @@ public function getFormId() { * {@inheritdoc} */ public function buildForm(array $form, array &$form_state) { - $period = drupal_map_assoc(array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, - 64800, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval'); + $intervals = array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200); + $period = array_map('format_interval', array_combine($intervals, $intervals)); $form['upload'] = array( '#type' => 'file', diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php index 767639e22932a64db4e7bb750122cc3173711ffb..45475275a3a094a027b76127a54035184ed94322 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php @@ -108,11 +108,12 @@ public function blockForm($form, &$form_state) { '#default_value' => $this->configuration['feed'], '#options' => $options, ); + $range = range(2, 20); $form['block_count'] = array( '#type' => 'select', '#title' => t('Number of news items in block'), '#default_value' => $this->configuration['block_count'], - '#options' => drupal_map_assoc(range(2, 20)), + '#options' => array_combine($range, $range), ); return $form; } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php index 3b892367b755acf2af17b1434f337fabf247c30d..4eefd7d8f91c7bd364d6b657305cbf9addd2c979 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php @@ -72,8 +72,12 @@ public static function create(ContainerInterface $container, array $configuratio public function buildConfigurationForm(array $form, array &$form_state) { $processors = $this->configuration['processors']; $info = $this->getPluginDefinition(); - $items = drupal_map_assoc(array(3, 5, 10, 15, 20, 25), array($this, 'formatItems')); - $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval'); + $counts = array(3, 5, 10, 15, 20, 25); + $items = array_map(function ($count) { + return format_plural($count, '1 item', '@count items'); + }, array_combine($counts, $counts)); + $intervals = array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800); + $period = array_map('format_interval', array_combine($intervals, $intervals)); $period[AGGREGATOR_CLEAR_NEVER] = t('Never'); $form['processors'][$info['id']] = array(); @@ -103,11 +107,16 @@ public function buildConfigurationForm(array $form, array &$form_state) { '#description' => t('Requires a correctly configured <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status'))), ); + $lengths = array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000); + $options = array_map(function($length) { + return ($length == 0) ? t('Unlimited') : format_plural($length, '1 character', '@count characters'); + }, array_combine($lengths, $lengths)); + $form['processors'][$info['id']]['aggregator_teaser_length'] = array( '#type' => 'select', '#title' => t('Length of trimmed description'), '#default_value' => $this->configuration['items']['teaser_length'], - '#options' => drupal_map_assoc(array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000), array($this, 'formatCharacters')), + '#options' => $options, '#description' => t('The maximum number of characters used in the trimmed version of content.'), ); return $form; @@ -233,32 +242,4 @@ public function setConfiguration(array $configuration) { $config->save(); } - /** - * Helper function for drupal_map_assoc. - * - * @param int $count - * Items count. - * - * @return string - * A string that is plural-formatted as "@count items". - */ - protected function formatItems($count) { - return format_plural($count, '1 item', '@count items'); - } - - /** - * Creates display text for teaser length option values. - * - * Callback for drupal_map_assoc() within settingsForm(). - * - * @param int $length - * The desired length of teaser text, in bytes. - * - * @return string - * A translated string explaining the teaser string length. - */ - protected function formatCharacters($length) { - return ($length == 0) ? t('Unlimited') : format_plural($length, '1 character', '@count characters'); - } - } diff --git a/core/modules/block/tests/Drupal/block/Tests/CategoryAutocompleteTest.php b/core/modules/block/tests/Drupal/block/Tests/CategoryAutocompleteTest.php index 026ad5c7249134e1f9fb56aedf0ead7b4644224a..5ff93f2657bad4e42daf122c8da4a14f92a67cfb 100644 --- a/core/modules/block/tests/Drupal/block/Tests/CategoryAutocompleteTest.php +++ b/core/modules/block/tests/Drupal/block/Tests/CategoryAutocompleteTest.php @@ -8,7 +8,6 @@ namespace Drupal\block\Tests; use Drupal\block\Controller\CategoryAutocompleteController; -use Drupal\Component\Utility\MapArray; use Drupal\Component\Utility\String; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\Request; @@ -63,7 +62,7 @@ public function setUp() { public function testAutocompleteSuggestions($string, $suggestions) { $suggestions = array_map(function ($suggestion) { return String::checkPlain($suggestion); - }, MapArray::copyValuesToKeys($suggestions)); + }, array_combine($suggestions, $suggestions)); $result = $this->autocompleteController->autocomplete(new Request(array('q' => $string))); $this->assertSame($suggestions, json_decode($result->getContent(), TRUE)); } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index e5054a46947ca1f5145281183f206300aa755cb2..a5fcb8ed0073fb9dcb17712cf3975ef562401d54 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -843,7 +843,7 @@ function comment_form_field_ui_field_edit_form_alter(&$form, $form_state) { if ($form['#field']->getType() == 'comment') { // We only support posting one comment at the time so it doesn't make sense // to let the site builder choose anything else. - $form['field']['cardinality_container']['cardinality']['#options'] = drupal_map_assoc(array(1)); + $form['field']['cardinality_container']['cardinality']['#options'] = array(1 => 1); $form['field']['cardinality_container']['#access'] = FALSE; } } @@ -1531,7 +1531,8 @@ function template_preprocess_comment_wrapper(&$variables) { * Returns an array of "comments per page" values that users can select from. */ function _comment_per_page() { - return drupal_map_assoc(array(10, 30, 50, 70, 90, 150, 200, 250, 300)); + $comments_per_page = array(10, 30, 50, 70, 90, 150, 200, 250, 300); + return array_combine($comments_per_page, $comments_per_page); } /** diff --git a/core/modules/config/lib/Drupal/config/Form/ConfigSingleExportForm.php b/core/modules/config/lib/Drupal/config/Form/ConfigSingleExportForm.php index cee2fb9530e319774d0f7d57fb868c7ccf63a3ef..c3b505e52ac8e8660edf03123e96ea5b16e922aa 100644 --- a/core/modules/config/lib/Drupal/config/Form/ConfigSingleExportForm.php +++ b/core/modules/config/lib/Drupal/config/Form/ConfigSingleExportForm.php @@ -7,7 +7,6 @@ namespace Drupal\config\Form; -use Drupal\Component\Utility\MapArray; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; @@ -182,7 +181,8 @@ protected function findConfiguration($config_type) { }, $this->definitions); // Find all config, and then filter our anything matching a config prefix. - $names = MapArray::copyValuesToKeys($this->configStorage->listAll()); + $names = $this->configStorage->listAll(); + $names = array_combine($names, $names); foreach ($names as $config_name) { foreach ($config_prefixes as $config_prefix) { if (strpos($config_name, $config_prefix) === 0) { diff --git a/core/modules/datetime/lib/Drupal/datetime/DateHelper.php b/core/modules/datetime/lib/Drupal/datetime/DateHelper.php index 55404460eb475bacbf159e6bcdfcd28ed2d42f16..93827221c36e22d87370bbd896717f5bdb558f64 100644 --- a/core/modules/datetime/lib/Drupal/datetime/DateHelper.php +++ b/core/modules/datetime/lib/Drupal/datetime/DateHelper.php @@ -292,7 +292,8 @@ public static function years($min = 0, $max = 0, $required = FALSE) { $max = intval(date('Y', REQUEST_TIME) + 3); } $none = array('' => ''); - $range = drupal_map_assoc(range($min, $max)); + $range = range($min, $max); + $range = array_combine($range, $range); return !$required ? $none + $range : $range; } @@ -323,7 +324,8 @@ public static function days($required = FALSE, $month = NULL, $year = NULL) { $max = 31; } $none = array('' => ''); - $range = drupal_map_assoc(range(1, $max)); + $range = range(1, $max); + $range = array_combine($range, $range); return !$required ? $none + $range : $range; } diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module index cd8e2c082c9ee3d0204c814beb70963d4c9c3a00..33f0120a85e1fcdc7533cc3df9dcd7116b2d8fcf 100644 --- a/core/modules/dblog/dblog.module +++ b/core/modules/dblog/dblog.module @@ -11,7 +11,6 @@ * @see watchdog() */ -use Drupal\Component\Utility\MapArray; use Drupal\Core\Database\Database; /** @@ -123,7 +122,7 @@ function _dblog_get_message_types() { $types[] = $object->type; } - return MapArray::copyValuesToKeys($types); + return array_combine($types, $types); } /** @@ -155,11 +154,12 @@ function dblog_watchdog(array $log_entry) { * Implements hook_form_FORM_ID_alter() for system_logging_settings(). */ function dblog_form_system_logging_settings_alter(&$form, $form_state) { + $row_limits = array(100, 1000, 10000, 100000, 1000000); $form['dblog_row_limit'] = array( '#type' => 'select', '#title' => t('Database log messages to keep'), '#default_value' => \Drupal::config('dblog.settings')->get('row_limit'), - '#options' => array(0 => t('All')) + drupal_map_assoc(array(100, 1000, 10000, 100000, 1000000)), + '#options' => array(0 => t('All')) + array_combine($row_limits, $row_limits), '#description' => t('The maximum number of messages to keep in the database log. Requires a <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status'))) ); diff --git a/core/modules/edit/lib/Drupal/edit/EditController.php b/core/modules/edit/lib/Drupal/edit/EditController.php index 2825383b716145caec11a85f671af0793185fda0..a2f602fc4683f906ba4ff29e5a2a46e78c555e18 100644 --- a/core/modules/edit/lib/Drupal/edit/EditController.php +++ b/core/modules/edit/lib/Drupal/edit/EditController.php @@ -12,7 +12,6 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Drupal\Component\Utility\MapArray; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Entity\EntityInterface; use Drupal\field\FieldInfo; @@ -221,7 +220,7 @@ public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view // Re-render the updated field for other view modes (i.e. for other // instances of the same logical field on the user's page). $other_view_mode_ids = $request->request->get('other_view_modes') ?: array(); - $other_view_modes = MapArray::copyValuesToKeys($other_view_mode_ids, $render_field_in_view_mode); + $other_view_modes = array_map($render_field_in_view_mode, array_combine($other_view_mode_ids, $other_view_mode_ids)); $response->addCommand(new FieldFormSavedCommand($output, $other_view_modes)); } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php index a9865cfe682125b5b447fb870f2924b858e18925..5105a202048b45a6f1bf9ed40cb97547ba9889c4 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php @@ -104,7 +104,8 @@ public static function settingsForm(FieldDefinitionInterface $field_definition) if ($target_type_info->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { // @todo Use Entity::getFieldDefinitions() when all entity types are // converted to the new Field API. - $fields = drupal_map_assoc(drupal_schema_fields_sql($entity_type->getBaseTable())); + $fields = drupal_schema_fields_sql($entity_type->getBaseTable()); + $fields = array_combine($fields, $fields); foreach (field_info_instances($target_type) as $bundle_instances) { foreach ($bundle_instances as $instance_name => $instance) { foreach ($instance->getField()->getColumns() as $column_name => $column_info) { diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/views/row/EntityReference.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/views/row/EntityReference.php index 0059b32e80626493523d8ce7657fa4612e1ba9fd..b975b0acd0218a8dc9ed10ab0d25b5b1f5a4516a 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/views/row/EntityReference.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/views/row/EntityReference.php @@ -52,7 +52,8 @@ public function preRender($row) { // Force all fields to be inline by default. if (empty($this->options['inline'])) { $fields = $this->view->getHandlers('field', $this->displayHandler->display['id']); - $this->options['inline'] = drupal_map_assoc(array_keys($fields)); + $names = array_keys($fields); + $this->options['inline'] = array_combine($names, $names); } return parent::preRender($row); diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index b5a9fa93d0c27fa1c4affe89ac69818ab54782c3..54657f29755aca2795c60e165901e0154057833c 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -7,7 +7,6 @@ namespace Drupal\field\Plugin\views\field; -use Drupal\Component\Utility\MapArray; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityStorageControllerInterface; @@ -414,7 +413,7 @@ public function buildOptionsForm(&$form, &$form_state) { $form['click_sort_column'] = array( '#type' => 'select', '#title' => t('Column used for click sorting'), - '#options' => drupal_map_assoc($column_names), + '#options' => array_combine($column_names, $column_names), '#default_value' => $this->options['click_sort_column'], '#description' => t('Used by Style: Table to determine the actual column to click sort the field on. The default is usually fine.'), ); @@ -500,7 +499,8 @@ function multiple_options_form(&$form, &$form_state) { } else { $type = 'select'; - $options = drupal_map_assoc(range(1, $field->getCardinality())); + $range = range(1, $field->getCardinality()); + $options = array_combine($range, $range); $size = 1; } $form['multi_type'] = array( @@ -599,9 +599,10 @@ public function buildGroupByForm(&$form, &$form_state) { // With "field API" fields, the column target of the grouping function // and any additional grouping columns must be specified. + $field_columns = array_keys($this->field_info->getColumns()); $group_columns = array( 'entity_id' => t('Entity ID'), - ) + MapArray::copyValuesToKeys(array_keys($this->field_info->getColumns()), 'ucfirst'); + ) + array_map('ucfirst', array_combine($field_columns, $field_columns)); $form['group_column'] = array( '#type' => 'select', @@ -611,8 +612,11 @@ public function buildGroupByForm(&$form, &$form_state) { '#options' => $group_columns, ); - $options = MapArray::copyValuesToKeys(array('bundle', 'language', 'entity_type'), 'ucfirst'); - + $options = array( + 'bundle' => 'Bundle', + 'language' => 'Language', + 'entity_type' => 'Entity_type', + ); // Add on defined fields, noting that they're prefixed with the field name. $form['group_columns'] = array( '#type' => 'checkboxes', diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php index 5323e4ef474db47cd1273f43e5cdc4afce1f26f8..5de03d987db72734caac19a5e238f447f25f8db8 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php @@ -258,6 +258,7 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, Ent $display_options = $entity_display->getComponent($field_name); $label = $field_definition->getLabel(); + $regions = array_keys($this->getRegions()); $field_row = array( '#attributes' => array('class' => array('draggable', 'tabledrag-leaf')), '#row_type' => 'field', @@ -282,7 +283,7 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, Ent '#type' => 'select', '#title' => $this->t('Label display for @title', array('@title' => $label)), '#title_display' => 'invisible', - '#options' => drupal_map_assoc(array_keys($this->getRegions())), + '#options' => array_combine($regions, $regions), '#empty_value' => '', '#attributes' => array('class' => array('field-parent')), '#parents' => array('fields', $field_name, 'parent'), @@ -432,6 +433,7 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, Ent protected function buildExtraFieldRow($field_id, $extra_field, EntityDisplayInterface $entity_display) { $display_options = $entity_display->getComponent($field_id); + $regions = array_keys($this->getRegions()); $extra_field_row = array( '#attributes' => array('class' => array('draggable', 'tabledrag-leaf')), '#row_type' => 'extra_field', @@ -453,7 +455,7 @@ protected function buildExtraFieldRow($field_id, $extra_field, EntityDisplayInte '#type' => 'select', '#title' => $this->t('Parents for @title', array('@title' => $extra_field['label'])), '#title_display' => 'invisible', - '#options' => drupal_map_assoc(array_keys($this->getRegions())), + '#options' => array_combine($regions, $regions), '#empty_value' => '', '#attributes' => array('class' => array('field-parent')), '#parents' => array('fields', $field_id, 'parent'), diff --git a/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php b/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php index 5e28958385b217d34638c133006d5ab52548555d..f4a955bd50abe6ebc15d6776f911dfd6958e0bda 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormBase; +use Drupal\Core\Render\Element; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -157,7 +158,8 @@ public function tablePreRender($elements) { $trees = array_fill_keys(array_keys($regions), $tree); $parents = array(); - $list = drupal_map_assoc(element_children($elements)); + $children = Element::children($elements); + $list = array_combine($children, $children); // Iterate on rows until we can build a known tree path for all of them. while ($list) { diff --git a/core/modules/forum/lib/Drupal/forum/ForumSettingsForm.php b/core/modules/forum/lib/Drupal/forum/ForumSettingsForm.php index e3c31fe570720af388294e00cad8f0bd948f6d4d..055516f9508471f3ab9b93193b2b5c5a8d30bc72 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumSettingsForm.php +++ b/core/modules/forum/lib/Drupal/forum/ForumSettingsForm.php @@ -27,20 +27,20 @@ public function getFormId() { public function buildForm(array $form, array &$form_state) { $config = $this->configFactory->get('forum.settings'); - $number = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400, 500)); + $options = array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400, 500); $form['forum_hot_topic'] = array( '#type' => 'select', '#title' => $this->t('Hot topic threshold'), '#default_value' => $config->get('topics.hot_threshold'), - '#options' => $number, + '#options' => array_combine($options, $options), '#description' => $this->t('The number of replies a topic must have to be considered "hot".'), ); - $number = drupal_map_assoc(array(10, 25, 50, 75, 100)); + $options = array(10, 25, 50, 75, 100); $form['forum_per_page'] = array( '#type' => 'select', '#title' => $this->t('Topics per page'), '#default_value' => $config->get('topics.page_limit'), - '#options' => $number, + '#options' => array_combine($options, $options), '#description' => $this->t('Default number of forum topics displayed per page.'), ); $forder = array( diff --git a/core/modules/forum/lib/Drupal/forum/Plugin/Block/ForumBlockBase.php b/core/modules/forum/lib/Drupal/forum/Plugin/Block/ForumBlockBase.php index c2ad994208edee90783fdeecd8cdb0965279eaf5..f1c2f4e60b7ca6e7ecb9d0d4bc04d425ae5fd405 100644 --- a/core/modules/forum/lib/Drupal/forum/Plugin/Block/ForumBlockBase.php +++ b/core/modules/forum/lib/Drupal/forum/Plugin/Block/ForumBlockBase.php @@ -39,11 +39,12 @@ public function access(AccountInterface $account) { * Overrides \Drupal\block\BlockBase::blockForm(). */ public function blockForm($form, &$form_state) { + $range = range(2, 20); $form['block_count'] = array( '#type' => 'select', '#title' => t('Number of topics'), '#default_value' => $this->configuration['block_count'], - '#options' => drupal_map_assoc(range(2, 20)), + '#options' => array_combine($range, $range), ); return $form; } diff --git a/core/modules/language/lib/Drupal/language/ConfigurableLanguageManager.php b/core/modules/language/lib/Drupal/language/ConfigurableLanguageManager.php index 3e0da615c2d42edcd8ffea3afef9bbfdae79bc1e..a7fb8f603b4500a3b4ca151871e798d9ff7ab625 100644 --- a/core/modules/language/lib/Drupal/language/ConfigurableLanguageManager.php +++ b/core/modules/language/lib/Drupal/language/ConfigurableLanguageManager.php @@ -8,7 +8,6 @@ namespace Drupal\language; use Drupal\Component\PhpStorage\PhpStorageFactory; -use Drupal\Component\Utility\MapArray; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\Language; @@ -323,7 +322,7 @@ public function getFallbackCandidates($langcode = NULL, array $context = array() // at the end. $candidates = array_keys($this->getLanguages()); $candidates[] = Language::LANGCODE_NOT_SPECIFIED; - $candidates = MapArray::copyValuesToKeys($candidates); + $candidates = array_combine($candidates, $candidates); // The first candidate should always be the desired language if specified. if (!empty($langcode)) { diff --git a/core/modules/locale/locale.translation.inc b/core/modules/locale/locale.translation.inc index 5ebe4279264bdbe1e8983a10ce92c5342ab4ff2f..fab2a21f279fee732ded14c9679a8d8c53d41032 100644 --- a/core/modules/locale/locale.translation.inc +++ b/core/modules/locale/locale.translation.inc @@ -73,7 +73,7 @@ function locale_translation_get_projects($project_names = array()) { // Return the requested project names or all projects. if ($project_names) { - return array_intersect_key($projects, drupal_map_assoc($project_names)); + return array_intersect_key($projects, array_combine($project_names, $project_names)); } return $projects; } diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Variable.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Variable.php index 1f4f816c1edeb5c6405a81665d797640e5e0f7f1..e9a24b5b0c2c0f50a0bf37847d407724b76d2c7d 100644 --- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Variable.php +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Variable.php @@ -46,7 +46,7 @@ public function count() { * {@inheritdoc} */ public function fields() { - return drupal_map_assoc($this->variables); + return array_combine($this->variables, $this->variables); } /** diff --git a/core/modules/node/lib/Drupal/node/NodeTypeFormController.php b/core/modules/node/lib/Drupal/node/NodeTypeFormController.php index e0a466c11281fd05a603490416801723b798b213..dda06828fbc9f6a806bc38e753b78e12ffe3edde 100644 --- a/core/modules/node/lib/Drupal/node/NodeTypeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeTypeFormController.php @@ -8,7 +8,6 @@ namespace Drupal\node; use Drupal\Core\Entity\EntityFormController; -use Drupal\Component\Utility\MapArray; use Drupal\Component\Utility\String; /** @@ -32,7 +31,8 @@ public function form(array $form, array &$form_state) { $node_settings = $type->getModuleSettings('node'); // Prepare node options to be used for 'checkboxes' form element. - $node_settings['options'] = MapArray::copyValuesToKeys(array_keys(array_filter($node_settings['options']))); + $keys = array_keys(array_filter($node_settings['options'])); + $node_settings['options'] = array_combine($keys, $keys); $form['name'] = array( '#title' => t('Name'), '#type' => 'textfield', diff --git a/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php index 6106729ab51d91e6e20223bab8c2f884d82d5de5..2c69b9f572c242571dfa8866de6bbb81b281094c 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php @@ -559,7 +559,8 @@ public function buildConfigurationForm(array $form, array &$form_state) { ); // Note: reversed to reflect that higher number = higher ranking. - $options = drupal_map_assoc(range(0, 10)); + $range = range(0, 10); + $options = array_combine($range, $range); foreach ($this->getRankings() as $var => $values) { $form['content_ranking']['factors']["rankings_$var"] = array( '#title' => $values['title'], diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/argument_validator/Node.php b/core/modules/node/lib/Drupal/node/Plugin/views/argument_validator/Node.php index fdb3415aa65e60506f09849d75e4c181c3d1e7c3..41f49a8fc640a4ba92b718193908ad42e3ea092c 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/argument_validator/Node.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/argument_validator/Node.php @@ -113,7 +113,7 @@ public function validateArgument($argument) { return FALSE; } - $test = drupal_map_assoc($nids->value); + $test = array_combine($nids->value, $nids->value); $titles = array(); $nodes = node_load_multiple($nids->value); diff --git a/core/modules/node/node.module b/core/modules/node/node.module index fb29b392825d0458cd0ed3a30804f388adb72b3d..b66ba18c5576f0b6c9bd31f83aee1800d1ff6c05 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1264,11 +1264,12 @@ function node_view_multiple($nodes, $view_mode = 'teaser', $langcode = NULL) { * @see node_form_system_site_information_settings_form_submit() */ function node_form_system_site_information_settings_form_alter(&$form, &$form_state, $form_id) { + $options = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30); $form['front_page']['default_nodes_main'] = array( '#type' => 'select', '#title' => t('Number of posts on front page'), '#default_value' => \Drupal::config('node.settings')->get('items_per_page'), - '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), + '#options' => array_combine($options, $options), '#access' => (\Drupal::config('system.site')->get('page.front') == 'node'), '#description' => t('The maximum number of posts displayed on overview pages such as the front page.'), ); diff --git a/core/modules/number/lib/Drupal/number/Plugin/Field/FieldFormatter/NumberDecimalFormatter.php b/core/modules/number/lib/Drupal/number/Plugin/Field/FieldFormatter/NumberDecimalFormatter.php index 1fe9c72d5294170ea3dc1ad531ea721a545c7f91..3b6ac2b5431ece54d9715c2f873c22f6b6ffccc2 100644 --- a/core/modules/number/lib/Drupal/number/Plugin/Field/FieldFormatter/NumberDecimalFormatter.php +++ b/core/modules/number/lib/Drupal/number/Plugin/Field/FieldFormatter/NumberDecimalFormatter.php @@ -44,10 +44,11 @@ public function settingsForm(array $form, array &$form_state) { '#default_value' => $this->getSetting('decimal_separator'), '#weight' => 5, ); + $range = range(0, 10); $elements['scale'] = array( '#type' => 'select', '#title' => t('Scale', array(), array('decimal places')), - '#options' => drupal_map_assoc(range(0, 10)), + '#options' => array_combine($range, $range), '#default_value' => $this->getSetting('scale'), '#description' => t('The number of digits to the right of the decimal.'), '#weight' => 6, diff --git a/core/modules/number/lib/Drupal/number/Plugin/Field/FieldType/DecimalItem.php b/core/modules/number/lib/Drupal/number/Plugin/Field/FieldType/DecimalItem.php index bba55918a0b835a2ffb1f565d0001942164f5c06..305d8b4303e4e8a1ffb9f496d3bf99bb097bbdaf 100644 --- a/core/modules/number/lib/Drupal/number/Plugin/Field/FieldType/DecimalItem.php +++ b/core/modules/number/lib/Drupal/number/Plugin/Field/FieldType/DecimalItem.php @@ -9,7 +9,6 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; -use Drupal\Component\Utility\MapArray; /** * Plugin implementation of the 'number_decimal' field type. @@ -67,18 +66,20 @@ public function settingsForm(array $form, array &$form_state, $has_data) { $element = array(); $settings = $this->getSettings(); + $range = range(10, 32); $element['precision'] = array( '#type' => 'select', '#title' => t('Precision'), - '#options' => MapArray::copyValuesToKeys(range(10, 32)), + '#options' => array_combine($range, $range), '#default_value' => $settings['precision'], '#description' => t('The total number of digits to store in the database, including those to the right of the decimal.'), '#disabled' => $has_data, ); + $range = range(0, 10); $element['scale'] = array( '#type' => 'select', '#title' => t('Scale', array(), array('decimal places')), - '#options' => MapArray::copyValuesToKeys(range(0, 10)), + '#options' => array_combine($range, $range), '#default_value' => $settings['scale'], '#description' => t('The number of digits to the right of the decimal.'), '#disabled' => $has_data, diff --git a/core/modules/options/tests/options_test.module b/core/modules/options/tests/options_test.module index 08b533ec6389feddd5ff7444e77d0d7e9f7fddc8..1416fa0e6ca9dcd54ef3698132441c1e86bbc91e 100644 --- a/core/modules/options/tests/options_test.module +++ b/core/modules/options/tests/options_test.module @@ -30,11 +30,12 @@ function options_test_allowed_values_callback(FieldDefinitionInterface $field_de */ function options_test_dynamic_values_callback(FieldDefinitionInterface $field_definition, EntityInterface $entity, &$cacheable) { $cacheable = FALSE; - // We need the values of the entity as keys. - return drupal_map_assoc(array( + $values = array( $entity->label(), $entity->url(), $entity->uuid(), $entity->bundle(), - )); + ); + // We need the values of the entity as keys. + return array_combine($values, $values); } diff --git a/core/modules/rest/lib/Drupal/rest/Plugin/views/style/Serializer.php b/core/modules/rest/lib/Drupal/rest/Plugin/views/style/Serializer.php index 2e7ac89f82aca9d52d6cb843787b8fc97cfcbecc..1f7e3a5397329024461b6a1fbf01bf2f7864bc45 100644 --- a/core/modules/rest/lib/Drupal/rest/Plugin/views/style/Serializer.php +++ b/core/modules/rest/lib/Drupal/rest/Plugin/views/style/Serializer.php @@ -95,7 +95,7 @@ public function buildOptionsForm(&$form, &$form_state) { '#type' => 'checkboxes', '#title' => t('Accepted request formats'), '#description' => t('Request formats that will be allowed in responses. If none are selected all formats will be allowed.'), - '#options' => drupal_map_assoc($this->formats), + '#options' => array_combine($this->formats, $this->formats), '#default_value' => $this->options['formats'], ); } diff --git a/core/modules/search/lib/Drupal/search/SearchPageListController.php b/core/modules/search/lib/Drupal/search/SearchPageListController.php index fbbe6bb09bc3741a91012fd4cf72bc1ff29c0485..a4975076770eec37ff673e8244d693a30e2aeb05 100644 --- a/core/modules/search/lib/Drupal/search/SearchPageListController.php +++ b/core/modules/search/lib/Drupal/search/SearchPageListController.php @@ -7,7 +7,6 @@ namespace Drupal\search; -use Drupal\Component\Utility\MapArray; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\Entity\DraggableListController; use Drupal\Core\Entity\EntityInterface; @@ -167,7 +166,8 @@ public function buildForm(array $form, array &$form_state) { '#submit' => array(array($this, 'searchAdminReindexSubmit')), ); - $items = MapArray::copyValuesToKeys(array(10, 20, 50, 100, 200, 500)); + $items = array(10, 20, 50, 100, 200, 500); + $items = array_combine($items, $items); // Indexing throttle: $form['indexing_throttle'] = array( diff --git a/core/modules/statistics/lib/Drupal/statistics/Plugin/Block/StatisticsPopularBlock.php b/core/modules/statistics/lib/Drupal/statistics/Plugin/Block/StatisticsPopularBlock.php index 64f71c4de874a6b13f04728a4493bc0cfffb033e..1a1976184894323da57a5139912781395843ce41 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Plugin/Block/StatisticsPopularBlock.php +++ b/core/modules/statistics/lib/Drupal/statistics/Plugin/Block/StatisticsPopularBlock.php @@ -79,7 +79,8 @@ public function access(AccountInterface $account) { */ public function blockForm($form, &$form_state) { // Popular content block settings. - $numbers = array('0' => t('Disabled')) + drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40)); + $numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40); + $numbers = array('0' => t('Disabled')) + array_combine($numbers, $numbers); $form['statistics_block_top_day_num'] = array( '#type' => 'select', '#title' => t("Number of day's top views to display"), diff --git a/core/modules/system/lib/Drupal/system/Form/CronForm.php b/core/modules/system/lib/Drupal/system/Form/CronForm.php index f32a4638ad0b73dbd381d6b2d824608bf7220e85..7c81ded1f0f5b9720a406ba4c3967e6627bde5d6 100644 --- a/core/modules/system/lib/Drupal/system/Form/CronForm.php +++ b/core/modules/system/lib/Drupal/system/Form/CronForm.php @@ -96,12 +96,13 @@ public function buildForm(array $form, array &$form_state) { '#type' => 'details', '#open' => TRUE, ); + $options = array(3600, 10800, 21600, 43200, 86400, 604800); $form['cron']['cron_safe_threshold'] = array( '#type' => 'select', '#title' => t('Run cron every'), '#description' => t('More information about setting up scheduled tasks can be found by <a href="@url">reading the cron tutorial on drupal.org</a>.', array('@url' => url('http://drupal.org/cron'))), '#default_value' => $config->get('threshold.autorun'), - '#options' => array(0 => t('Never')) + drupal_map_assoc(array(3600, 10800, 21600, 43200, 86400, 604800), 'format_interval'), + '#options' => array(0 => t('Never')) + array_map('format_interval', array_combine($options, $options)), ); return parent::buildForm($form, $form_state); diff --git a/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php b/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php index a123d8b54fbea279b7accfd529e188c2f7175723..6e7d9d666d1931f1ccd6915e584001723b32c9a6 100644 --- a/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php +++ b/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php @@ -80,7 +80,8 @@ public function buildForm(array $form, array &$form_state) { '#open' => TRUE, ); - $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval'); + $period = array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400); + $period = array_map('format_interval', array_combine($period, $period)); $period[0] = '<' . t('none') . '>'; $form['caching']['page_cache_maximum_age'] = array( '#type' => 'select', diff --git a/core/modules/system/lib/Drupal/system/Form/RssFeedsForm.php b/core/modules/system/lib/Drupal/system/Form/RssFeedsForm.php index dd791ced318e4bb6b9a56f638c81194d1a8fa849..b18cdfe366cf2973b89cbc16a24e72deec16923e 100644 --- a/core/modules/system/lib/Drupal/system/Form/RssFeedsForm.php +++ b/core/modules/system/lib/Drupal/system/Form/RssFeedsForm.php @@ -32,11 +32,12 @@ public function buildForm(array $form, array &$form_state) { '#default_value' => $rss_config->get('channel.description'), '#description' => t('Description of your site, included in each feed.') ); + $options = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30); $form['feed_default_items'] = array( '#type' => 'select', '#title' => t('Number of items in each feed'), '#default_value' => $rss_config->get('items.limit'), - '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), + '#options' => array_combine($options, $options), '#description' => t('Default number of items to include in each feed.') ); $form['feed_item_length'] = array( diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php index e819056abd75388ccae3bf7eade82c4b8be34712..286599186c3998999cd6bd969f685915b71b23d3 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php @@ -7,7 +7,6 @@ namespace Drupal\system\Tests\Entity; -use Drupal\Component\Utility\MapArray; use Drupal\Core\Language\Language; use Drupal\entity_test\Entity\EntityTestMulRev; @@ -495,7 +494,7 @@ function testLanguageFallback() { $controller = $this->entityManager->getViewBuilder($entity_type); $build = $controller->view($entity); $this->assertEqual($build['label']['#markup'], $values[$current_langcode]['name'], 'By default the entity is rendered in the current language.'); - $langcodes = MapArray::copyValuesToKeys($this->langcodes); + $langcodes = array_combine($this->langcodes, $this->langcodes); // We have no translation for the $langcode2 langauge, hence the expected // result is the topmost existing translation, that is $langcode. $langcodes[$langcode2] = $langcode; diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index c1d42bf6ca64148e9c5508e540599c470e69ff72..9620ef50b572e351852f46009761c88c3330b823 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -54,7 +54,7 @@ function entity_test_entity_types($filter = NULL) { $types[] = 'entity_test_rev'; } $types[] = 'entity_test_mulrev'; - return drupal_map_assoc($types); + return array_combine($types, $types); } /** diff --git a/core/modules/system/tests/modules/form_test/form_test.module b/core/modules/system/tests/modules/form_test/form_test.module index e80170829e6521c38e169aeb38b132567a50d4a8..de5c2f037b81d05fc09ef3b41c74a2482897d4bf 100644 --- a/core/modules/system/tests/modules/form_test/form_test.module +++ b/core/modules/system/tests/modules/form_test/form_test.module @@ -140,7 +140,7 @@ function form_test_validate_form_validate(&$form, &$form_state) { * @deprecated Use \Drupal\form_test\validateRequiredForm() */ function form_test_validate_required_form($form, &$form_state) { - $options = drupal_map_assoc(array('foo', 'bar')); + $options = array('foo' => 'foo', 'bar' => 'bar'); $validate = array('form_test_validate_required_form_element_validate'); $form['textfield'] = array( @@ -882,7 +882,7 @@ function form_test_select($form, &$form_state) { $base = array( '#type' => 'select', - '#options' => drupal_map_assoc(array('one', 'two', 'three')), + '#options' => array('one' => 'one', 'two' => 'two', 'three' => 'three'), ); $form['select'] = $base + array( diff --git a/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/TestPluginBag.php b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/TestPluginBag.php index c389308cdfa2bad5998fa7234e2df12b838deda2..9c8c7c093af78d2ddab20d75057a73bb7ba24f6f 100644 --- a/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/TestPluginBag.php +++ b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/TestPluginBag.php @@ -9,7 +9,6 @@ use Drupal\Component\Plugin\PluginBag; use Drupal\Component\Plugin\PluginManagerInterface; -use Drupal\Component\Utility\MapArray; /** * Defines a plugin bag which uses fruit plugins. @@ -32,7 +31,8 @@ class TestPluginBag extends PluginBag { public function __construct(PluginManagerInterface $manager) { $this->manager = $manager; - $this->instanceIDs = MapArray::copyValuesToKeys(array_keys($this->manager->getDefinitions())); + $instance_ids = array_keys($this->manager->getDefinitions()); + $this->instanceIDs = array_combine($instance_ids, $instance_ids); } /** diff --git a/core/modules/user/lib/Drupal/user/Plugin/entity_reference/selection/UserSelection.php b/core/modules/user/lib/Drupal/user/Plugin/entity_reference/selection/UserSelection.php index dc7475f3fdc536d92c872c4e5ece378663d5970d..71f0c3f3c98e9a0130a03603394885d92458d413 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/entity_reference/selection/UserSelection.php +++ b/core/modules/user/lib/Drupal/user/Plugin/entity_reference/selection/UserSelection.php @@ -67,7 +67,7 @@ public static function settingsForm(FieldDefinitionInterface $field_definition) '#type' => 'checkboxes', '#title' => t('Restrict to the selected roles'), '#required' => TRUE, - '#options' => array_diff_key(user_role_names(TRUE), drupal_map_assoc(array(DRUPAL_AUTHENTICATED_RID))), + '#options' => array_diff_key(user_role_names(TRUE), array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID)), '#default_value' => $selection_handler_settings['filter']['role'], ); } diff --git a/core/modules/views/lib/Drupal/views/EventSubscriber/RouteSubscriber.php b/core/modules/views/lib/Drupal/views/EventSubscriber/RouteSubscriber.php index 4188c474e2e1d2e9e9919c8ab23d3830ad40e170..94b3ff4a48d2446f0bc0bad1655b895f9d0ed7ca 100644 --- a/core/modules/views/lib/Drupal/views/EventSubscriber/RouteSubscriber.php +++ b/core/modules/views/lib/Drupal/views/EventSubscriber/RouteSubscriber.php @@ -7,7 +7,6 @@ namespace Drupal\views\EventSubscriber; -use Drupal\Component\Utility\MapArray; use Drupal\Core\Page\HtmlPage; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\KeyValueStore\StateInterface; @@ -104,7 +103,7 @@ protected function getViewsDisplayIDsWithRoute() { $id = $view->storage->id(); $this->viewsDisplayPairs[] = $id . '.' . $display_id; } - $this->viewsDisplayPairs = MapArray::copyValuesToKeys($this->viewsDisplayPairs); + $this->viewsDisplayPairs = array_combine($this->viewsDisplayPairs, $this->viewsDisplayPairs); } return $this->viewsDisplayPairs; } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/argument/String.php b/core/modules/views/lib/Drupal/views/Plugin/views/argument/String.php index a2dd29b5a7dfe6eaef4c0c2c1c7c1448697a2f5d..af3176bca3e2b2414a787353b7fa4b073b524648 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/argument/String.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/argument/String.php @@ -284,7 +284,7 @@ function title() { * Override for specific title lookups. */ public function titleQuery() { - return drupal_map_assoc($this->value, '\Drupal\Component\Utility\String::checkPlain'); + return array_map('\Drupal\Component\Utility\String::checkPlain', array_combine($this->value, $this->value)); } public function summaryName($data) { diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/cache/Time.php b/core/modules/views/lib/Drupal/views/Plugin/views/cache/Time.php index 3db6bfabb197df38321a880a2f7fdabc7731eb66..054f545e99efc5fa34174e4271c8b2860df47c6f 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/cache/Time.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/cache/Time.php @@ -40,7 +40,7 @@ protected function defineOptions() { public function buildOptionsForm(&$form, &$form_state) { parent::buildOptionsForm($form, $form_state); $options = array(60, 300, 1800, 3600, 21600, 518400); - $options = drupal_map_assoc($options, 'format_interval'); + $options = array_map('format_interval', array_combine($options, $options)); $options = array(-1 => t('Never cache')) + $options + array('custom' => t('Custom')); $form['results_lifespan'] = array( diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php index 1521e2fe81e6a1cda1eaf01f5d8d7f207de36b42..7416f1045f2685664484b43d9aad37172062a9f8 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php @@ -860,7 +860,7 @@ protected function defaultDisplayFiltersUser(array $form, array &$form_state) { $handler = $table_data[$bundle_key]['filter']['id']; $handler_definition = Views::pluginManager('filter')->getDefinition($handler); if ($handler == 'in_operator' || is_subclass_of($handler_definition['class'], 'Drupal\\views\\Plugin\\views\\filter\\InOperator')) { - $value = drupal_map_assoc(array($form_state['values']['show']['type'])); + $value = array($form_state['values']['show']['type'] => $form_state['values']['show']['type']); } // Otherwise, use just a single value. else { diff --git a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php index f8b2e4cfeae9cb957fc579df8f53abb5aef82270..81e692fecf3dbfad2852cb8cd85ce1814306a90d 100644 --- a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php @@ -192,7 +192,8 @@ public function testArchiveView() { $view = views_get_view('archive'); $view->setDisplay('page_1'); $this->executeView($view); - $column_map = drupal_map_assoc(array('nid', 'created_year_month', 'num_records')); + $columns = array('nid', 'created_year_month', 'num_records'); + $column_map = array_combine($columns, $columns); // Create time of additional nodes created in the setup method. $created_year_month = date('Ym', REQUEST_TIME - 3600); $expected_result = array( diff --git a/core/modules/views/lib/Drupal/views/Tests/Entity/FilterEntityBundleTest.php b/core/modules/views/lib/Drupal/views/Tests/Entity/FilterEntityBundleTest.php index db0022194248798deafaf49a8e8e28610750238c..0d7ee5d8d493cf8215b01b3955c245499c6b48d5 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Entity/FilterEntityBundleTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Entity/FilterEntityBundleTest.php @@ -95,7 +95,7 @@ public function testFilterEntity() { // Test each bundle type. $view->initDisplay(); $filters = $view->display_handler->getOption('filters'); - $filters['type']['value'] = drupal_map_assoc(array($key)); + $filters['type']['value'] = array($key => $key); $view->display_handler->setOption('filters', $filters); $this->executeView($view); @@ -107,7 +107,7 @@ public function testFilterEntity() { // Test an invalid bundle type to make sure we have no results. $view->initDisplay(); $filters = $view->display_handler->getOption('filters'); - $filters['type']['value'] = drupal_map_assoc(array('type_3')); + $filters['type']['value'] = array('type_3' => 'type_3'); $view->display_handler->setOption('filters', $filters); $this->executeView($view); diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php index 3d0675866a427a586a778e013ba5f37ef9cc255b..fadc4217bf2d27cc9613863b5593a1e645a63857 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php @@ -309,7 +309,7 @@ public function testPropertyMethods() { $this->assertIdentical(spl_object_hash($view->getResponse()), spl_object_hash($new_response), 'New response object correctly set.'); // Test the generateHandlerId() method. - $test_ids = drupal_map_assoc(array('test', 'test_1')); + $test_ids = array('test' => 'test', 'test_1' => 'test_1'); $this->assertEqual($view->generateHandlerId('new', $test_ids), 'new'); $this->assertEqual($view->generateHandlerId('test', $test_ids), 'test_2'); diff --git a/core/modules/views/lib/Drupal/views/Views.php b/core/modules/views/lib/Drupal/views/Views.php index ba45e1768fd312b0ef769da5eeb469a945d46140..40c5cd1773b049fdadeb94031fab7826e2485182 100644 --- a/core/modules/views/lib/Drupal/views/Views.php +++ b/core/modules/views/lib/Drupal/views/Views.php @@ -7,7 +7,6 @@ namespace Drupal\views; -use Drupal\Component\Utility\MapArray; use Drupal\Component\Utility\String; /** @@ -150,7 +149,7 @@ public static function getPluginDefinitions() { public static function getEnabledDisplayExtenders() { $enabled = array_filter((array) \Drupal::config('views.settings')->get('display_extenders')); - return MapArray::copyValuesToKeys($enabled); + return array_combine($enabled, $enabled); } /** diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 8a55f4bdbbc76b6f3a235b9fd43d7d00f10aed78..8cb4cd214f50df1b766cdbdc410d725613497022 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -398,10 +398,11 @@ function template_preprocess_views_view_summary(&$variables) { $url_options['query'] = $view->exposed_raw_input; } - $active_urls = drupal_map_assoc(array( + $active_urls = array( url(current_path(), array('alias' => TRUE)), // force system path url(current_path()), // could be an alias - )); + ); + $active_urls = array_combine($active_urls, $active_urls); // Collect all arguments foreach row, to be able to alter them for example // by the validator. This is not done per single argument value, because this @@ -456,12 +457,13 @@ function template_preprocess_views_view_summary_unformatted(&$variables) { } $count = 0; - $active_urls = drupal_map_assoc(array( + $active_urls = array( // Force system path. url(current_path(), array('alias' => TRUE)), // Could be an alias. url(current_path()), - )); + ); + $active_urls = array_combine($active_urls, $active_urls); // Collect all arguments for each row, to be able to alter them for example // by the validator. This is not done per single argument value, because diff --git a/core/tests/Drupal/Tests/Component/Utility/MapArrayTest.php b/core/tests/Drupal/Tests/Component/Utility/MapArrayTest.php deleted file mode 100644 index 4b833fa41d7ecc65c87cea2ce533093f4e2e2400..0000000000000000000000000000000000000000 --- a/core/tests/Drupal/Tests/Component/Utility/MapArrayTest.php +++ /dev/null @@ -1,105 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\Tests\Component\Utility\MapArrayTest. - */ - -namespace Drupal\Tests\Component\Utility; - -use Drupal\Tests\UnitTestCase; -use Drupal\Component\Utility\MapArray; - -/** - * Tests the MapArray system. - * - * @see \Drupal\Component\Utility\MapArray - */ -class MapArrayTest extends UnitTestCase { - - public static function getInfo() { - return array( - 'name' => 'MapArray test', - 'description' => 'Test that the MapArray functions work properly.', - 'group' => 'Bootstrap', - ); - } - - /** - * Tests MapArray::copyValuesToKey() input against expected output. - * - * @dataProvider providerCopyValuesToKey - * - * @param array $input - * The input array for the MapArray::copyValuesToKey() method. - * @param array $expected - * The expected output from calling the method. - * @param callable $callable - * The optional callable. - * - * @see \Drupal\Component\Utility\MapArray::copyValuesToKey() - * @see \Drupal\Tests\Component\Utility\MapArrayTest::providerCopyValuesToKey() - */ - public function testCopyValuesToKey(array $input, array $expected, $callable = NULL) { - $output = MapArray::copyValuesToKeys($input, $callable); - $this->assertEquals($expected, $output); - } - - /** - * Data provider for MapArray::copyValuesToKey(). - * - * @return array - * An array of tests, matching the parameter inputs for testCopyValuesToKey. - * - * @see \Drupal\Component\Utility\MapArray::copyValuesToKey() - * @see \Drupal\Tests\Component\Utility\MapArrayTest::testCopyValuesToKey() - */ - public function providerCopyValuesToKey() { - // Test an empty array. - $tests[] = array( - array(), - array() - ); - - // Tests the creation of an associative array. - $tests[] = array( - array('foobar'), - array('foobar' => 'foobar') - ); - - // Tests overwriting indexes with their value. - $tests[] = array( - array('foo' => 'bar'), - array('bar' => 'bar') - ); - - // Tests using the callback function. - $tests[] = array( - array(1, 2, 3, 4, 5), - array( - 1 => 2, - 2 => 4, - 3 => 6, - 4 => 8, - 5 => 10, - ), - 'Drupal\Tests\Component\Utility\MapArrayTest::providerCopyValuesToKeyCallback', - ); - - return $tests; - } - - /** - * Callback for a test in providerCopyValuesToKey(), which doubles the value. - * - * @param int $n - * The value passed in from array_map(). - * - * @return int - * The doubled integer value. - */ - public static function providerCopyValuesToKeyCallback($n) { - return $n * 2; - } - -}