diff --git a/core/lib/Drupal/Core/Config/Entity/Condition.php b/core/lib/Drupal/Core/Config/Entity/Condition.php new file mode 100644 index 0000000..f23177c --- /dev/null +++ b/core/lib/Drupal/Core/Config/Entity/Condition.php @@ -0,0 +1,71 @@ +entityType); + $config_prefix = $info['config_prefix']; + $options = '-H '; + $postfix = " $query->directory/$config_prefix.*.yml"; + foreach ($this->conditions as $condition) { + switch ($condition['op']) { + case '=': + case NULL: + $commands[] = "grep $options\"^ *" . $condition['field'] . ': \'\?' . $condition['value'] . '\'\?$"' . $postfix; + break; + } + $options = ''; + } + exec(implode('|', $commands), $output); + $cut_length = strlen($query->directory) + strlen($config_prefix) + 2; + $ids = array(); + foreach ($output as $line) { + preg_match('/^([^.]+)\./', substr($line, $cut_length), $matches); + $ids[] = $matches[1]; + } + return $ids; + } + + /** + * Implements Drupal\Core\Entity\Query\ConditionInterface::exists(). + */ + public function exists($field, $langcode = NULL) { + } + + /** + * Implements Drupal\Core\Entity\Query\ConditionInterface::notExists(). + */ + public function notExists($field, $langcode = NULL) { + } + + protected function translateCondition(&$condition) { + switch ($condition['operator']) { + case 'STARTS_WITH': + break; + + case 'CONTAINS': + break; + + case 'ENDS_WITH': + break; + + } + } + +} diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index 6d0a3f4..8187dfc 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -428,6 +428,6 @@ 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.php b/core/lib/Drupal/Core/Config/Entity/Query.php new file mode 100644 index 0000000..d73cd3d --- /dev/null +++ b/core/lib/Drupal/Core/Config/Entity/Query.php @@ -0,0 +1,39 @@ +directory = $directory; + } + + /** + * Implements Drupal\Core\Entity\Query\QueryInterface::conditionGroupFactory(). + */ + public function conditionGroupFactory($conjunction = 'AND') { + return new Condition($conjunction); + } + + /** + * Implements Drupal\Core\Entity\Query\QueryInterface::execute(). + */ + public function execute() { + $query = new \stdClass; + $query->directory = $this->directory; + $query->entityType = $this->entityType; + return $this->condition->compile($query); + } + +} diff --git a/core/lib/Drupal/Core/Config/Entity/QueryFactory.php b/core/lib/Drupal/Core/Config/Entity/QueryFactory.php new file mode 100644 index 0000000..a944f03 --- /dev/null +++ b/core/lib/Drupal/Core/Config/Entity/QueryFactory.php @@ -0,0 +1,22 @@ +directory = $directory; + } + + function get($entity_type, $conjunction) { + return new Query($entity_type, $conjunction, $this->directory); + } +} diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index 48684e5..8d25f11 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -67,6 +67,9 @@ public function build(ContainerBuilder $container) { // Add the entity query factory. $container->register('entity.query', 'Drupal\Core\Entity\Query\QueryFactory') ->addArgument(new Reference('service_container')); + // @todo: replace with active config storage refernece once it is in CoreBundle. + $container->register('entity.query.config', 'Drupal\Core\Config\Entity\QueryFactory') + ->addArgument(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY)); $container->register('router.dumper', 'Drupal\Core\Routing\MatcherDumper') ->addArgument(new Reference('database'));