Commit fdcf584b authored by catch's avatar catch

Issue #2340701 by prics, martin107: Use array_diff_key() more in core.

parent c6f02381
......@@ -367,7 +367,7 @@ protected function createExtensionChangelist() {
}, $module_list);
// Determine which modules to uninstall.
$uninstall = array_diff(array_keys($current_extensions['module']), array_keys($new_extensions['module']));
$uninstall = array_keys(array_diff_key($current_extensions['module'], $new_extensions['module']));
// Sort the list of newly uninstalled extensions by their weights, so that
// dependencies are uninstalled last. Extensions of the same weight are
// sorted in reverse alphabetical order, to ensure the order is exactly
......@@ -388,7 +388,7 @@ protected function createExtensionChangelist() {
$uninstall = array_intersect(array_keys($module_list), $uninstall);
// Determine which modules to install.
$install = array_diff(array_keys($new_extensions['module']), array_keys($current_extensions['module']));
$install = array_keys(array_diff_key($new_extensions['module'], $current_extensions['module']));
// Ensure that installed modules are sorted in exactly the reverse order
// (with dependencies installed first, and modules of the same weight sorted
// in alphabetical order).
......@@ -396,8 +396,8 @@ protected function createExtensionChangelist() {
$install = array_intersect(array_keys($module_list), $install);
// Work out what themes to install and to uninstall.
$theme_install = array_diff(array_keys($new_extensions['theme']), array_keys($current_extensions['theme']));
$theme_uninstall = array_diff(array_keys($current_extensions['theme']), array_keys($new_extensions['theme']));
$theme_install = array_keys(array_diff_key($new_extensions['theme'], $current_extensions['theme']));
$theme_uninstall = array_keys(array_diff_key($current_extensions['theme'], $new_extensions['theme']));
$this->extensionChangelist = array(
'module' => array(
......
......@@ -80,7 +80,7 @@ function hook_field_storage_config_update_forbid(\Drupal\field\FieldStorageConfi
// Forbid any update that removes allowed values with actual data.
$allowed_values = $field_storage->getSetting('allowed_values');
$prior_allowed_values = $prior_field_storage->getSetting('allowed_values');
$lost_keys = array_diff(array_keys($prior_allowed_values), array_keys($allowed_values));
$lost_keys = array_keys(array_diff_key($prior_allowed_values,$allowed_values));
if (_options_values_in_use($field_storage->entity_type, $field_storage->getName(), $lost_keys)) {
throw new \Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException(t('A list field (@field_name) with existing data cannot have its keys changed.', array('@field_name' => $field_storage->getName())));
}
......
......@@ -99,7 +99,7 @@ function options_field_storage_config_update_forbid(FieldStorageConfigInterface
// Forbid any update that removes allowed values with actual data.
$allowed_values = $field_storage->getSetting('allowed_values');
$prior_allowed_values = $prior_field_storage->getSetting('allowed_values');
$lost_keys = array_diff(array_keys($prior_allowed_values), array_keys($allowed_values));
$lost_keys = array_keys(array_diff_key($prior_allowed_values, $allowed_values));
if (_options_values_in_use($field_storage->entity_type, $field_storage->getName(), $lost_keys)) {
throw new FieldStorageDefinitionUpdateForbiddenException(t('A list field (@field_name) with existing data cannot have its keys changed.', array('@field_name' => $field_storage->getName())));
}
......
......@@ -150,7 +150,7 @@ public static function validateAllowedValues($element, FormStateInterface $form_
// Prevent removing values currently in use.
if ($element['#field_has_data']) {
$lost_keys = array_diff(array_keys($element['#allowed_values']), array_keys($values));
$lost_keys = array_keys(array_diff_key($element['#allowed_values'], $values));
if (_options_values_in_use($element['#entity_type'], $element['#field_name'], $lost_keys)) {
$form_state->setError($element, t('Allowed values list: some values are being removed while currently in use.'));
}
......
......@@ -82,7 +82,7 @@ public function testUserListing() {
);
}
$this->assertFalse(array_diff(array_keys($result_accounts), array_keys($accounts)), 'Ensure all accounts are listed.');
$this->assertFalse(array_keys(array_diff_key($result_accounts, $accounts)), 'Ensure all accounts are listed.');
foreach ($result_accounts as $name => $values) {
$this->assertEqual($values['status'] == t('active'), $accounts[$name]->status->value, 'Ensure the status is displayed properly.');
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment