public static function ConfigBit::actionAdd in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.4
Same name and namespace in other branches
- 8.8 src/Config/ConfigBit.php \Drupal\varbase\Config\ConfigBit::actionAdd()
- 8.5 src/Config/ConfigBit.php \Drupal\varbase\config\ConfigBit::actionAdd()
- 8.6 src/Config/ConfigBit.php \Drupal\varbase\config\ConfigBit::actionAdd()
- 8.7 src/Config/ConfigBit.php \Drupal\varbase\config\ConfigBit::actionAdd()
- 9.0.x src/Config/ConfigBit.php \Drupal\varbase\Config\ConfigBit::actionAdd()
Applay the action of adding config bit in to the parent file.
Parameters
string $config_bit_file_name: Config bit file name in the root configbit folder.
string $condition_name: Condition name in the config bit file.
string|bool $condition_value: Condition value for the condition name in the config bit file.
string $target: Targent item in the parent config file.
File
- src/
Config/ ConfigBit.php, line 178
Class
- ConfigBit
- Defines config bit to help in managing custom config which used in install.
Namespace
Drupal\varbase\configCode
public static function actionAdd($config_bit_file_name, $condition_name, $condition_value, $target, $type = 'profile', $project = 'varbase') {
$config_bit_data = ConfigBit::getConfigBit($config_bit_file_name, $type, $project);
if (isset($config_bit_data['type']) && $config_bit_data['type'] == 'action' && isset($config_bit_data['for']) && !empty($config_bit_data['for']) && file_exists(drupal_get_path($type, $project) . '/' . $config_bit_data['for']) && isset($config_bit_data['action']) && isset($config_bit_data['action']['add']) && isset($config_bit_data['action']['add']['when']) && isset($config_bit_data['action']['add']['when'][$condition_name]) && $config_bit_data['action']['add']['when'][$condition_name] == $condition_value && isset($config_bit_data['action']['add']['target']) && $config_bit_data['action']['add']['target'] == $target && isset($config_bit_data['action']['add'][$target])) {
$config_target_data = Yaml::parse(file_get_contents(drupal_get_path($type, $project) . '/' . $config_bit_data['for']));
$configs_to_add = $config_bit_data['action']['add'][$target];
foreach ($configs_to_add as $config_to_add) {
if (!in_array($config_to_add, $config_target_data[$target])) {
$config_target_data[$target][] = (string) $config_to_add;
}
}
// Dump the array to string of Yaml format.
$updated_config_target = Yaml::dump($config_target_data, 2, 2);
// Save the updated config to the target file.
file_put_contents(drupal_get_path($type, $project) . '/' . $config_bit_data['for'], $updated_config_target);
}
}