diff --git a/core/lib/Drupal/Core/Config/Entity/Query/Query.php b/core/lib/Drupal/Core/Config/Entity/Query/Query.php index 8627198..105c7d4 100644 --- a/core/lib/Drupal/Core/Config/Entity/Query/Query.php +++ b/core/lib/Drupal/Core/Config/Entity/Query/Query.php @@ -121,7 +121,7 @@ protected function loadRecords() { $prefix_length = strlen($prefix); // Search the conditions for restrictions on configuration object names. - $names = array(); + $names = FALSE; if ($this->condition->getConjunction() == 'AND') { foreach ($this->condition->conditions() as $condition) { $operator = $condition['operator'] ?: (is_array($condition['value']) ? 'IN' : '='); @@ -143,7 +143,12 @@ protected function loadRecords() { } else if ($lookup_type == 'NOT UNIQUE') { foreach ($this->configKeyStore->getMultiple($keys) as $list) { - $names = array_merge($names, $list); + if (is_array($names)) { + $names = array_merge($names, $list); + } + else { + $names = $list; + } } } } @@ -158,7 +163,7 @@ protected function loadRecords() { } } // If no restrictions on IDs were found, we need to parse all records. - if (!$names) { + if ($names === FALSE) { $names = $this->configFactory->listAll($prefix); } diff --git a/core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php b/core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php index 9faf6e1..8dbe0ae 100644 --- a/core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php +++ b/core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php @@ -90,17 +90,19 @@ protected function getKeyValueStore(EntityTypeInterface $entity_type) { */ protected function updateConfigKeyStore(EntityTypeInterface $entity_type, Config $config) { $config_key_store = $this->getKeyValueStore($entity_type); - foreach ($entity_type->getLookups() as $key => $type) { - $value = $config->get($key); - $key = $key . ':' . $value; - if ($type == 'UNIQUE') { - $config_key_store->set($key, $config->getName()); - } - else if ($type == 'NOT UNIQUE') { - $values = $config_key_store->get($key, []); - if (!in_array($config->getName(), $values, TRUE)) { - $values[] = $config->getName(); - $config_key_store->set($key, $values); + foreach ($entity_type->getLookups() as $lookup_key => $type) { + foreach($this->getKeys($lookup_key, $config) as $key) { + if ($type == 'UNIQUE') { + $config_key_store->set($key, $config->getName()); + } + else { + if ($type == 'NOT UNIQUE') { + $values = $config_key_store->get($key, []); + if (!in_array($config->getName(), $values, TRUE)) { + $values[] = $config->getName(); + $config_key_store->set($key, $values); + } + } } } } @@ -116,27 +118,49 @@ protected function updateConfigKeyStore(EntityTypeInterface $entity_type, Config */ protected function deleteConfigKeyStore(EntityTypeInterface $entity_type, Config $config) { $config_key_store = $this->getKeyValueStore($entity_type); - foreach ($entity_type->getLookups() as $key => $type) { - $value = $config->getOriginal($key); - $key = $key . ':' . $value; - if ($type == 'UNIQUE') { - $config_key_store->delete($key); - } - else if ($type == 'NOT UNIQUE') { - $values = $config_key_store->get($key, []); - if ($pos = array_search($config->getName(), $values, TRUE)) { - unset($values[$pos]); - } - if (empty($values)) { + foreach ($entity_type->getLookups() as $lookup_key => $type) { + foreach($this->getKeys($lookup_key, $config, 'getOriginal') as $key) { + if ($type == 'UNIQUE') { $config_key_store->delete($key); } else { - $config_key_store->set($key, $values); + if ($type == 'NOT UNIQUE') { + $values = $config_key_store->get($key, []); + if ($pos = array_search($config->getName(), $values, TRUE)) { + unset($values[$pos]); + } + if (empty($values)) { + $config_key_store->delete($key); + } + else { + $config_key_store->set($key, $values); + } + } } } } } + protected function getKeys($key, Config $config, $get_method = 'get') { + $parts = explode('.*.', $key); + $values = (array) $this->getValues($config, $parts, $parts[0], $get_method); + return array_map(function($value) use ($key) { return $key . ':' . $value; }, $values); + } + + protected function getValues(Config $config, $parts, $key, $get_method = 'get', $start = 0) { + $value = $config->$get_method($key); + if (is_array($value)) { + $new_value = []; + $start++; + foreach (array_keys($value) as $key_bit) { + $new_key = $key . '.' . $key_bit . '.' . $parts[$start]; + $new_value[] = $this->getValues($config, $parts, $new_key, $get_method, $start); + } + $value = $new_value; + } + return $value; + } + /** * Updates configuration entity in the key store. * diff --git a/core/modules/tour/src/Entity/Tour.php b/core/modules/tour/src/Entity/Tour.php index d50caa9..6b6817f 100644 --- a/core/modules/tour/src/Entity/Tour.php +++ b/core/modules/tour/src/Entity/Tour.php @@ -24,6 +24,9 @@ * entity_keys = { * "id" = "id", * "label" = "label" + * }, + * lookups = { + * "routes.*.route_name" = "NOT UNIQUE" * } * ) */