protected function ConfigBit::processConfigBits in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.8
Same name and namespace in other branches
- 9.0.x src/Config/ConfigBit.php \Drupal\varbase\Config\ConfigBit::processConfigBits()
Process Config Bits.
Parameters
array $supportedConfigType: The supported config type.
\Drupal\Core\Config\Config $saved_config: The saved config.
1 call to ConfigBit::processConfigBits()
- ConfigBit::configSave in src/
Config/ ConfigBit.php - React to a config object being saved.
File
- src/
Config/ ConfigBit.php, line 196
Class
- ConfigBit
- Class ConfigBit.
Namespace
Drupal\varbase\ConfigCode
protected function processConfigBits(array $supportedConfigType, Config $saved_config) {
// Get saved cofnig name.
$saved_config_name = $saved_config
->getName();
// Get token variant for entity type name.
$token_variant = $this->configFactory
->getEditable($saved_config_name)
->get($supportedConfigType['token_variant']);
// Have the config template file name.
$config_template_file = DRUPAL_ROOT . '/' . drupal_get_path('profile', 'varbase') . '/configbit/varbase_config_templates/' . $supportedConfigType['config_template_file'];
if (file_exists($config_template_file)) {
// Get config file contents.
$config_template_file_contents = file_get_contents($config_template_file);
// Using string manipulation to replace the entity type token with
// the current entity type name.
$config_template_file_contents = str_replace($supportedConfigType['token'], $token_variant, $config_template_file_contents);
// Parse the yml file content to an array of data.
$config_template_file_data = (array) Yaml::parse($config_template_file_contents);
if (isset($config_template_file_data['config_bits']) && is_array($config_template_file_data['config_bits'])) {
foreach ($config_template_file_data['config_bits'] as $target_config_bit_name => $target_config_bit_actions) {
// Get the config bit factory for the current config bit changes.
$target_config_bit_factory = $this->configFactory
->getEditable($target_config_bit_name);
$save_actions = 0;
if (isset($target_config_bit_actions) && is_array($target_config_bit_actions) && count($target_config_bit_actions) > 0) {
foreach ($target_config_bit_actions as $config_action) {
// Add config action.
if (isset($config_action['add']) && $this
->validateDependencies($config_action['add']) && $this
->applyConfigActionAdd($config_action['add'], $target_config_bit_name, $target_config_bit_factory)) {
$save_actions++;
}
// Remove config action.
if (isset($config_action['remove']) && $this
->validateDependencies($config_action['remove']) && $this
->applyConfigActionRemove($config_action['remove'], $target_config_bit_name, $target_config_bit_factory)) {
$save_actions++;
}
// Import new config if config does not exists.
if (isset($config_action['import']) && $this
->validateDependencies($config_action['import']) && $this
->applyConfigActionImport($config_action['import'], $target_config_bit_name, $target_config_bit_factory)) {
$save_actions++;
}
}
if ($save_actions > 0) {
// Save target config after finishing all config action changes.
$target_config_bit_factory
->save(TRUE);
// Flushes plugins caches on requisted.
if (isset($supportedConfigType['plugin.cache_clearer']) && $supportedConfigType['plugin.cache_clearer'] == TRUE) {
$this->pluginCacheClearer
->clearCachedDefinitions();
}
}
}
}
}
}
}