function QueryFactory::getKeys

Same name in other branches
  1. 9 core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php \Drupal\Core\Config\Entity\Query\QueryFactory::getKeys()
  2. 10 core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php \Drupal\Core\Config\Entity\Query\QueryFactory::getKeys()
  3. 11.x core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php \Drupal\Core\Config\Entity\Query\QueryFactory::getKeys()

Creates lookup keys for configuration data.

Parameters

\Drupal\Core\Config\Config $config: The configuration object.

string $key: The configuration key to look for.

string $get_method: Which method on the config object to call to get the value. Either 'get' or 'getOriginal'.

\Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type: The configuration entity type.

Return value

array An array of lookup keys concatenated to the configuration values.

Throws

\Drupal\Core\Config\Entity\Query\InvalidLookupKeyException The provided $key cannot end with a wildcard. This makes no sense since you cannot do fast lookups against this.

2 calls to QueryFactory::getKeys()
QueryFactory::deleteConfigKeyStore in core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php
Deletes lookup data.
QueryFactory::updateConfigKeyStore in core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php
Updates or adds lookup data.

File

core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php, line 154

Class

QueryFactory
Provides a factory for creating entity query objects for the config backend.

Namespace

Drupal\Core\Config\Entity\Query

Code

protected function getKeys(Config $config, $key, $get_method, ConfigEntityTypeInterface $entity_type) {
    if (substr($key, -1) == '*') {
        throw new InvalidLookupKeyException(strtr('%entity_type lookup key %key ends with a wildcard this can not be used as a lookup', [
            '%entity_type' => $entity_type->id(),
            '%key' => $key,
        ]));
    }
    $parts = explode('.*', $key);
    // Remove leading dots.
    array_walk($parts, function (&$value) {
        $value = trim($value, '.');
    });
    $values = (array) $this->getValues($config, $parts[0], $get_method, $parts);
    $output = [];
    // Flatten the array to a single dimension and add the key to all the
    // values.
    array_walk_recursive($values, function ($current) use (&$output, $key) {
        if (is_scalar($current)) {
            $current = $key . ':' . $current;
        }
        $output[] = $current;
    });
    return $output;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.