public static function ConfigBit::actionAdd in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.8
Same name and namespace in other branches
- 8.4 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()
Apply the action of adding config bit in to the parent file.
Parameters
string $config_bit_file_name: The Config bit file name in the root configbit folder.
string $condition_name: The Condition name in the config bit file.
string|bool $condition_value: The Condition value for the condition name in the config bit file.
string $target: The Target item in the parent config file.
string $type: The type of profile.
string $project: The project.
File
- src/
Config/ ConfigBit.php, line 765
Class
- ConfigBit
- Class ConfigBit.
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);
}
}