Skip to content

Instantly share code, notes, and snippets.

@JPustkuchen
Last active February 9, 2022 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JPustkuchen/97484749425867f3b570288208a56df5 to your computer and use it in GitHub Desktop.
Save JPustkuchen/97484749425867f3b570288208a56df5 to your computer and use it in GitHub Desktop.
Check if configuration with given name exists (like "has()") in active configuration.
<?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;
}
?>
@JPustkuchen
Copy link
Author

JPustkuchen commented Feb 9, 2022

I was looking for something like $activeConfigFactory->has() but that doesn't exist. Here's the workaround to check the existence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment