You are here

public static function ConfigBit::actionRemove in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.5

Same name and namespace in other branches
  1. 8.8 src/Config/ConfigBit.php \Drupal\varbase\Config\ConfigBit::actionRemove()
  2. 8.4 src/Config/ConfigBit.php \Drupal\varbase\config\ConfigBit::actionRemove()
  3. 8.6 src/Config/ConfigBit.php \Drupal\varbase\config\ConfigBit::actionRemove()
  4. 8.7 src/Config/ConfigBit.php \Drupal\varbase\config\ConfigBit::actionRemove()
  5. 9.0.x src/Config/ConfigBit.php \Drupal\varbase\Config\ConfigBit::actionRemove()

Applay the action of removing config bit from 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 225

Class

ConfigBit
Defines config bit to help in managing custom config which used in install.

Namespace

Drupal\varbase\config

Code

public static function actionRemove($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']) && $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']['remove']) && isset($config_bit_data['action']['remove']['when']) && isset($config_bit_data['action']['remove']['when'][$condition_name]) && $config_bit_data['action']['remove']['when'][$condition_name] == $condition_value && isset($config_bit_data['action']['remove']['target']) && $config_bit_data['action']['remove']['target'] == $target && isset($config_bit_data['action']['remove'][$target])) {

    // Read the Yaml config file. which this config bit for.
    $config_target_data = Yaml::parse(file_get_contents(drupal_get_path($type, $project) . '/' . $config_bit_data['for']));
    $configs_to_remove = $config_bit_data['action']['remove'][$target];
    foreach ($configs_to_remove as $config_to_remove) {
      $config_to_remove_key = array_search((string) $config_to_remove, $config_target_data[$target], TRUE);
      if ($config_to_remove_key !== FALSE) {
        unset($config_target_data[$target][$config_to_remove_key]);
      }
    }

    // Save the updated config to the target file.
    $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);
  }
}