function ConfigConfigurator::__construct

Same name in other branches
  1. 10 core/lib/Drupal/Core/Recipe/ConfigConfigurator.php \Drupal\Core\Recipe\ConfigConfigurator::__construct()

Parameters

array $config: Config options for a recipe.

string $recipe_directory: The path to the recipe.

\Drupal\Core\Config\StorageInterface $active_configuration: The active configuration storage.

File

core/lib/Drupal/Core/Recipe/ConfigConfigurator.php, line 29

Class

ConfigConfigurator
@internal This API is experimental.

Namespace

Drupal\Core\Recipe

Code

public function __construct(array $config, string $recipe_directory, StorageInterface $active_configuration) {
    $this->recipeConfigDirectory = is_dir($recipe_directory . '/config') ? $recipe_directory . '/config' : NULL;
    // @todo Consider defaulting this to FALSE in https://drupal.org/i/3478669.
    $this->strict = $config['strict'] ?? TRUE;
    $recipe_storage = $this->getConfigStorage();
    if ($this->strict === TRUE) {
        $strict_list = $recipe_storage->listAll();
    }
    else {
        $strict_list = $this->strict ?: [];
    }
    // Everything in the strict list needs to be identical in the recipe and
    // active storage.
    foreach ($strict_list as $config_name) {
        if ($active_data = $active_configuration->read($config_name)) {
            // @todo https://www.drupal.org/i/3439714 Investigate if there is any
            //   generic code in core for this.
            unset($active_data['uuid'], $active_data['_core']);
            if (empty($active_data['dependencies'])) {
                unset($active_data['dependencies']);
            }
            $recipe_data = $recipe_storage->read($config_name);
            if (empty($recipe_data['dependencies'])) {
                unset($recipe_data['dependencies']);
            }
            // Ensure we don't get a false mismatch due to differing key order.
            // @todo When https://www.drupal.org/project/drupal/issues/3230826 is
            //   fixed in core, use that API instead to sort the config data.
            self::recursiveSortByKey($active_data);
            self::recursiveSortByKey($recipe_data);
            if ($active_data !== $recipe_data) {
                throw new RecipePreExistingConfigException($config_name, sprintf("The configuration '%s' exists already and does not match the recipe's configuration", $config_name));
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.