function RecipeRunner::processConfiguration

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

Creates configuration and applies configuration actions.

Parameters

\Drupal\Core\Recipe\Recipe $recipe: The recipe being applied.

2 calls to RecipeRunner::processConfiguration()
RecipeRunner::installConfig in core/lib/Drupal/Core/Recipe/RecipeRunner.php
Installs a config for a recipe.
RecipeRunner::processRecipe in core/lib/Drupal/Core/Recipe/RecipeRunner.php

File

core/lib/Drupal/Core/Recipe/RecipeRunner.php, line 97

Class

RecipeRunner
Applies a recipe.

Namespace

Drupal\Core\Recipe

Code

protected static function processConfiguration(Recipe $recipe) : void {
    
    /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
    $config_manager = \Drupal::service(ConfigManagerInterface::class);
    $config_installer = new RecipeConfigInstaller(\Drupal::service('config.factory'), \Drupal::service('config.storage'), \Drupal::service('config.typed'), $config_manager, \Drupal::service('event_dispatcher'), NULL, \Drupal::service('extension.path.resolver'));
    $config = $recipe->config;
    // Create configuration that is either supplied by the recipe or listed in
    // the config.import section that does not exist.
    $config_installer->installRecipeConfig($config);
    if (!empty($config->config['actions'])) {
        $values = $recipe->input
            ->getValues();
        // Wrap the replacement strings with `${` and `}`, which is a fairly
        // common style of placeholder.
        $keys = array_map(fn($k) => sprintf('${%s}', $k), array_keys($values));
        $replace = array_combine($keys, $values);
        // Process the actions.
        
        /** @var \Drupal\Core\Config\Action\ConfigActionManager $config_action_manager */
        $config_action_manager = \Drupal::service('plugin.manager.config_action');
        foreach ($config->config['actions'] as $config_name => $actions) {
            // If this config name contains an input value, it must begin with the
            // config prefix of a known entity type.
            if (str_contains($config_name, '${') && empty($config_manager->getEntityTypeIdByName($config_name))) {
                throw new ConfigActionException("The entity type for the config name '{$config_name}' could not be identified.");
            }
            $config_name = str_replace($keys, $replace, $config_name);
            foreach ($actions as $action_id => $data) {
                $config_action_manager->applyAction($action_id, $config_name, static::replaceInputValues($data, $replace));
            }
        }
    }
}

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