class RecipeConfigInstaller

Same name in other branches
  1. 10 core/lib/Drupal/Core/Recipe/RecipeConfigInstaller.php \Drupal\Core\Recipe\RecipeConfigInstaller

Extends the ConfigInstaller service for recipes.

@internal This API is experimental.

Hierarchy

Expanded class hierarchy of RecipeConfigInstaller

File

core/lib/Drupal/Core/Recipe/RecipeConfigInstaller.php, line 19

Namespace

Drupal\Core\Recipe
View source
final class RecipeConfigInstaller extends ConfigInstaller {
    
    /**
     * {@inheritdoc}
     */
    public function installRecipeConfig(ConfigConfigurator $recipe_config) : void {
        $storage = $recipe_config->getConfigStorage();
        // Build the list of new configuration to create.
        $list = array_diff($storage->listAll(), $this->getActiveStorages()
            ->listAll());
        // If there is nothing to do.
        if (empty($list)) {
            return;
        }
        $config_to_create = $storage->readMultiple($list);
        // Sort $config_to_create in the order of the least dependent first.
        $dependency_manager = new ConfigDependencyManager();
        $dependency_manager->setData($config_to_create);
        $config_to_create = array_merge(array_flip($dependency_manager->sortAll()), $config_to_create);
        // Create the optional configuration if there is any left after filtering.
        if (!empty($config_to_create)) {
            $this->createConfiguration(StorageInterface::DEFAULT_COLLECTION, $config_to_create);
        }
        // Validation during the installer is hard. For example:
        // Drupal\ckeditor5\Plugin\Validation\Constraint\EnabledConfigurablePluginsConstraintValidator
        // ends up calling _ckeditor5_theme_css() via
        // Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition->validateDrupalAspects()
        // and this expects the theme system to be set up correctly but we're in the
        // installer so this cannot happen.
        // @todo https://www.drupal.org/i/3443603 consider adding a validation step
        //   for recipes to the installer via install_tasks().
        if (InstallerKernel::installationAttempted()) {
            return;
        }
        foreach (array_keys($config_to_create) as $name) {
            // All config objects are mappings.
            
            /** @var \Drupal\Core\Config\Schema\Mapping $typed_config */
            $typed_config = $this->typedConfig
                ->createFromNameAndData($name, $this->configFactory
                ->get($name)
                ->getRawData());
            foreach ($typed_config->getConstraints() as $constraint) {
                // Only validate the config if it has explicitly been marked as being
                // validatable.
                if ($constraint instanceof FullyValidatableConstraint) {
                    
                    /** @var \Symfony\Component\Validator\ConstraintViolationList $violations */
                    $violations = $typed_config->validate();
                    if (count($violations) > 0) {
                        throw new InvalidConfigException($violations, $typed_config);
                    }
                    break;
                }
            }
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ConfigInstaller::$activeStorages protected property The active configuration storages, keyed by collection.
ConfigInstaller::$configFactory protected property The configuration factory.
ConfigInstaller::$configManager protected property The configuration manager.
ConfigInstaller::$eventDispatcher protected property The event dispatcher.
ConfigInstaller::$extensionPathResolver protected property The extension path resolver.
ConfigInstaller::$installProfile protected property The name of the currently active installation profile.
ConfigInstaller::$isSyncing protected property Is configuration being created as part of a configuration sync.
ConfigInstaller::$sourceStorage protected property The configuration storage that provides the default configuration.
ConfigInstaller::$typedConfig protected property The typed configuration manager.
ConfigInstaller::checkConfigurationToInstall public function Checks the configuration that will be installed for an extension. Overrides ConfigInstallerInterface::checkConfigurationToInstall
ConfigInstaller::createConfiguration protected function Creates configuration in a collection based on the provided list.
ConfigInstaller::drupalGetProfile protected function Gets the install profile from settings.
ConfigInstaller::findDefaultConfigWithUnmetDependencies protected function Finds default configuration with unmet dependencies.
ConfigInstaller::findPreExistingConfiguration protected function Finds pre-existing configuration objects for the provided extension.
ConfigInstaller::getActiveStorages protected function Gets the configuration storage that provides the active configuration.
ConfigInstaller::getConfigToCreate protected function Gets configuration data from the provided storage to create.
ConfigInstaller::getDefaultConfigDirectory protected function Gets an extension's default configuration directory.
ConfigInstaller::getEnabledExtensions protected function Gets the list of enabled extensions including both modules and themes.
ConfigInstaller::getMissingDependencies protected function Returns an array of missing dependencies for a config object.
ConfigInstaller::getProfileStorages protected function Gets the profile storage to use to check for profile overrides.
ConfigInstaller::getSourceStorage public function Gets the configuration storage that provides the default configuration. Overrides ConfigInstallerInterface::getSourceStorage
ConfigInstaller::installCollectionDefaultConfig public function Installs all default configuration in the specified collection. Overrides ConfigInstallerInterface::installCollectionDefaultConfig
ConfigInstaller::installDefaultConfig public function Installs the default configuration of a given extension. Overrides ConfigInstallerInterface::installDefaultConfig
ConfigInstaller::installOptionalConfig public function Installs optional configuration. Overrides ConfigInstallerInterface::installOptionalConfig
ConfigInstaller::isSyncing public function Gets the syncing state. Overrides ConfigInstallerInterface::isSyncing
ConfigInstaller::setSourceStorage public function Sets the configuration storage that provides the default configuration. Overrides ConfigInstallerInterface::setSourceStorage
ConfigInstaller::setSyncing public function Sets the status of the isSyncing flag. Overrides ConfigInstallerInterface::setSyncing
ConfigInstaller::validateDependencies protected function Validates an array of config data that contains dependency information.
ConfigInstaller::__construct public function Constructs the configuration installer.
RecipeConfigInstaller::installRecipeConfig public function

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