Last active
February 9, 2022 17:52
-
-
Save JPustkuchen/97484749425867f3b570288208a56df5 to your computer and use it in GitHub Desktop.
Check if configuration with given name exists (like "has()") in active configuration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Helper function / example code to check | |
* if the given configuration (by name) | |
* exists in active configuration. | |
* @param string $configName | |
* The id of the configuration to check. | |
* | |
* @return boolean | |
* | |
/* | |
function isInActiveConfig($configId = 'core.extension'){ | |
$activeConfigFactory = \Drupal::service('config.factory'); | |
// The config factory always returns an ImmutableConfig object | |
// but if doesn't exist in configuration yet, ->isNew() is true. | |
$existsInActiveConfig = !$activeConfigFactory->get($configId)->isNew(); | |
return $existsInActiveConfig; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was looking for something like
$activeConfigFactory->has()
but that doesn't exist. Here's the workaround to check the existence.