diff --git a/core/lib/Drupal/Core/Config/Entity/Query/Query.php b/core/lib/Drupal/Core/Config/Entity/Query/Query.php index d86b0f1..b29b179 100644 --- a/core/lib/Drupal/Core/Config/Entity/Query/Query.php +++ b/core/lib/Drupal/Core/Config/Entity/Query/Query.php @@ -155,43 +155,42 @@ protected function loadRecords() { } // If no restrictions on IDs were found, we need to parse all records. else { - $all_names = $this->configStorage->listAll($prefix); - // In case we have an ID condition, try to filter down the list of config + $names = $this->configStorage->listAll($prefix); + // In case we have an ID condition, try to narrow down the list of config // objects to load. if ($id_condition) { - $names = array(); - foreach ($all_names as $name) { - $id = substr($name, $prefix_length); + $value = $id_condition['value']; + $filter = NULL; switch ($id_condition['operator']) { case '<>': - if ($id != $id_condition['value']) { - $names[] = $name; - } + $filter = function ($name) use ($value, $prefix_length) { + $id = substr($name, $prefix_length); + return $id !== $value; + }; break; case 'STARTS_WITH': - if (strpos($id, $id_condition['value']) === 0) { - $names[] = $name; - } + $filter = function ($name) use ($value, $prefix_length) { + $id = substr($name, $prefix_length); + return strpos($id, $value) === 0; + }; break; case 'CONTAINS': - if (strpos($id, $id_condition['value']) !== FALSE) { - $names[] = $name; - } + $filter = function ($name) use ($value, $prefix_length) { + $id = substr($name, $prefix_length); + return strpos($id, $value) !== FALSE; + }; break; case 'ENDS_WITH': - if (strrpos($id, $id_condition['value']) === strlen($id) - strlen($id_condition['value'])) { - $names[] = $name; - } - break; - default: - $names[] = $name; + $filter = function ($name) use ($value, $prefix_length) { + $id = substr($name, $prefix_length); + return strrpos($id, $value) === strlen($id) - strlen($value); + }; break; } + if ($filter) { + $names = array_filter($names, $filter); + } } - } - else { - $names = $all_names; - } } // Load the corresponding records.