QueryFactory::getKeys

protected QueryFactory::getKeys(Config $config, $key, $get_method, ConfigEntityTypeInterface $entity_type)

Creates lookup keys for configuration data.

Parameters

\Drupal\Core\Config\Config $config: The configuration object. @param 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.

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 = array();
  // 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;
}
doc_Drupal
2016-10-29 09:35:54
Comments
Leave a Comment

Please login to continue.