Example #1
0
 /**
  * Creates lookup keys for configuration data.
  *
  * @param \Drupal\Core\Config\Config $config
  *   The configuration object.
  *  @param string $key
  *   The configuration key to look for.
  * @param string $get_method
  *   Which method on the config object to call to get the value. Either 'get'
  *   or 'getOriginal'.
  * @param \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type
  *   The configuration entity type.
  *
  * @return 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.
  */
 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;
 }