summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-09-19 10:51:04 (GMT)
committerNathaniel Catchpole2016-09-19 10:51:42 (GMT)
commitd20b2b3bb07b67e200241db36bfa58a798acab3f (patch)
tree61ea66058304501abf8c57b6b1afd060b4674af2
parent441357f2864ffd9d78b8c14b31356cdbfd1622fa (diff)
Issue #2762549 by alexpott, Fabianx, Mixologic, xjm: Drupal\field\Tests\Update\FieldUpdateTest, Drupal\views\Tests\Update\EntityViewsDataUpdateTest and Drupal\comment\Tests\CommentFieldsTest fail
-rw-r--r--core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php37
1 files changed, 35 insertions, 2 deletions
diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
index ef522ad..0dc1971 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
@@ -174,11 +174,35 @@ class ConfigDependencyManager {
// always after field storages. This is because field storages need to be
// created before a field.
$graph = $this->getGraph();
- uasort($graph, array($this, 'sortGraph'));
+ $sorts = $this->prepareMultisort($graph, ['weight', 'name']);
+ array_multisort($sorts['weight'], SORT_DESC, SORT_NUMERIC, $sorts['name'], SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE, $graph);
return array_replace(array_intersect_key($graph, $dependencies), $dependencies);
}
/**
+ * Extracts data from the graph for use in array_multisort().
+ *
+ * @param array $graph
+ * The graph to extract data from.
+ * @param array $keys
+ * The keys whose values to extract.
+ *
+ * @return
+ * An array keyed by the $keys passed in. The values are arrays keyed by the
+ * row from the graph and the value is the corresponding value for the key
+ * from the graph.
+ */
+ protected function prepareMultisort($graph, $keys) {
+ $return = array_fill_keys($keys, []);
+ foreach ($graph as $graph_key => $graph_row) {
+ foreach ($keys as $key) {
+ $return[$key][$graph_key] = $graph_row[$key];
+ }
+ }
+ return $return;
+ }
+
+ /**
* Sorts the dependencies in order of most dependent last.
*
* @return array
@@ -189,7 +213,8 @@ class ConfigDependencyManager {
$graph = $this->getGraph();
// Sort by weight and alphabetically. The most dependent entities
// are last and entities with the same weight are alphabetically ordered.
- uasort($graph, array($this, 'sortGraphByWeight'));
+ $sorts = $this->prepareMultisort($graph, ['weight', 'name']);
+ array_multisort($sorts['weight'], SORT_ASC, SORT_NUMERIC, $sorts['name'], SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE, $graph);
// Use array_intersect_key() to exclude modules and themes from the list.
return array_keys(array_intersect_key($graph, $this->data));
}
@@ -197,6 +222,10 @@ class ConfigDependencyManager {
/**
* Sorts the dependency graph by weight and alphabetically.
*
+ * @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. Use
+ * \Drupal\Core\Config\Entity\ConfigDependencyManager::prepareMultisort() and
+ * array_multisort() instead.
+ *
* @param array $a
* First item for comparison. The compared items should be associative
* arrays that include a 'weight' and a 'name' key.
@@ -218,6 +247,10 @@ class ConfigDependencyManager {
/**
* Sorts the dependency graph by reverse weight and alphabetically.
*
+ * @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. Use
+ * \Drupal\Core\Config\Entity\ConfigDependencyManager::prepareMultisort() and
+ * array_multisort() instead.
+ *
* @param array $a
* First item for comparison. The compared items should be associative
* arrays that include a 'weight' and a 'name' key.