diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index b472b8f..f8b4c45 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -424,7 +424,7 @@ protected function invokeHook($hook, EntityInterface $entity) { * Implements Drupal\Core\Entity\EntityStorageControllerInterface::getQueryServicename(). */ public function getQueryServicename() { - throw new \LogicException('Querying configuration entities is not supported.'); + return 'entity.query.config'; } /** diff --git a/core/lib/Drupal/Core/Config/Entity/Query/Condition.php b/core/lib/Drupal/Core/Config/Entity/Query/Condition.php new file mode 100644 index 0000000..b1d0d3c --- /dev/null +++ b/core/lib/Drupal/Core/Config/Entity/Query/Condition.php @@ -0,0 +1,36 @@ +connection = $connection; + } + + /** + * @param \Drupal\Core\Config\ConfigEvent $event + * The config object being written. + */ + public function configSave(ConfigEvent $event) { + $txn = $this->connection->startTransaction(); + $this->configDelete($event); + if ($this->entity_type) { + $this->connection->insert('ceqd') + ->fields('entity_type', 'entity_id', 'name', 'value') + ->values($this->flatten($this->config->get())) + ->execute(); + } + } + + public function configDelete(ConfigEvent $event) { + $this->config = $event->getConfig(); + $name = $this->config->getName(); + if ($this->entity_type = config_get_entity_type_by_name($name)) { + $this->entity_id = substr($name, strlen($this->entity_type) + 1); + $this->connection->delete('ceqd') + ->condition('entity_type', $this->entity_type) + ->condition('entity_id', $this->entity_id) + ->execute(); + } + } + + /** + * @param $data + * The contents of the config object. + * @param array $values + * A list of insert values. Each value is a list of $entity_type, + * $entity_id, a flattened config key (for eg. + * display.default.display_title) and the value. + * @param string $prefix + * The current config prefix. + */ + protected function flatten($data, array &$values = array(), $prefix = '') { + foreach ($data as $key => $value) { + if (is_array($value)) { + $this->flatten($value, $values, "$key."); + } + else { + $values[] = array($this->entity_type, $this->entity_id, "$prefix$key", $value); + } + } + return $values; + } + + /** + * Implements \Symfony\Component\EventDispatcher\EventSubscriberInterface::getSubscribedEvents(). + * + * @return array + */ + public static function getSubscribedEvents() { + $events['config.save'][] = array('configSave', 20); + $events['config.delete'][] = array('configDelete', 20); + return $events; + } +} diff --git a/core/lib/Drupal/Core/Config/Entity/Query/Query.php b/core/lib/Drupal/Core/Config/Entity/Query/Query.php new file mode 100644 index 0000000..8f10129 --- /dev/null +++ b/core/lib/Drupal/Core/Config/Entity/Query/Query.php @@ -0,0 +1,17 @@ +connection = $connection; + } + + function get($entity_type, $conjunction = 'AND') { + return new Query($entity_type, $conjunction, $this->connection); + } +} diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index e9d6d2f..2ddae5f 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -137,6 +137,8 @@ public function build(ContainerBuilder $container) { // Add the entity query factory. $container->register('entity.query', 'Drupal\Core\Entity\Query\QueryFactory') ->addArgument(new Reference('service_container')); + $container->register('entity.query.config', 'Drupal\Core\Config\Entity\Query\QueryFactory') + ->addArgument(new Reference('database')); $container->register('router.dumper', 'Drupal\Core\Routing\MatcherDumper') ->addArgument(new Reference('database'));