function ConfigActionManager::getConfigNamesMatchingExpression
Same name in other branches
- 11.x core/lib/Drupal/Core/Config/Action/ConfigActionManager.php \Drupal\Core\Config\Action\ConfigActionManager::getConfigNamesMatchingExpression()
Gets the names of all active config objects that match an expression.
Parameters
string $expression: The expression to match. This may be the full name of a config object, or it may contain wildcards (to target all config entities of a specific type, or a subset thereof). For example:
- `user.role.*` would target all user roles.
- `user.role.anonymous` would target only the anonymous user role.
- `core.entity_view_display.node.*.default` would target the default view display of every content type.
- `core.entity_form_display.*.*.default` would target the default form display of every bundle of every entity type.
The expression MUST begin with the prefix of a config entity type -- for example, `field.field.` in the case of fields, or `user.role.` for user roles. The prefix cannot contain wildcards.
Return value
string[] The names of all active config objects that match the expression.
Throws
\Drupal\Core\Config\Action\ConfigActionException Thrown if the expression does not match any known config entity type's prefix, or if the expression cannot be parsed.
1 call to ConfigActionManager::getConfigNamesMatchingExpression()
- ConfigActionManager::applyAction in core/
lib/ Drupal/ Core/ Config/ Action/ ConfigActionManager.php - Applies a config action.
File
-
core/
lib/ Drupal/ Core/ Config/ Action/ ConfigActionManager.php, line 186
Class
Namespace
Drupal\Core\Config\ActionCode
private function getConfigNamesMatchingExpression(string $expression) : array {
// If there are no wildcards, we can return the config name as-is.
if (!str_contains($expression, '.*')) {
return [
$expression,
];
}
$entity_type = $this->configManager
->getEntityTypeIdByName($expression);
if (empty($entity_type)) {
throw new ConfigActionException("No installed config entity type uses the prefix in the expression '{$expression}'. Either there is a typo in the expression or this recipe should install an additional module or depend on another recipe.");
}
/** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type */
$entity_type = $this->configManager
->getEntityTypeManager()
->getDefinition($entity_type);
$prefix = $entity_type->getConfigPrefix();
// Convert the expression to a regular expression. We assume that * should
// match the characters allowed by
// \Drupal\Core\Config\ConfigBase::validateName(), which is permissive.
$expression = str_replace('\\*', '[^.:?*<>"\'\\/\\\\]+', preg_quote($expression));
$matches = @preg_grep("/^{$expression}\$/", $this->configStorage
->listAll("{$prefix}."));
if ($matches === FALSE) {
throw new ConfigActionException("The expression '{$expression}' could not be parsed.");
}
return $matches;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.