You are here

function bootstrap_paragraphs_update_configuration_from_yml in Bootstrap Paragraphs 8.2

Updates a configuration from yml file.

Parameters

string $ymlFileName: Yml file name (without .yml suffix).

array $sets: An array of what needs to be set.

  • The key will be what we are setting (Can have . in string for array).
  • The value is the key that will be used from the new config file (Can have . in string for array).

For example if you are updating 'content' with 'content' from the new config file, $sets would be ['content' => 'content'].

File

./bootstrap_paragraphs.install, line 41
Install, uninstall and update hooks for Bootstrap Paragraphs module.

Code

function bootstrap_paragraphs_update_configuration_from_yml($ymlFileName, array $sets) {
  $bp_path = drupal_get_path('module', 'bootstrap_paragraphs');
  $yml = Yaml::parse(file_get_contents($bp_path . '/config/optional/' . $ymlFileName . '.yml'));
  $config = \Drupal::configFactory()
    ->getEditable($ymlFileName);
  foreach ($sets as $key => $value) {
    $parts = explode('.', $value);
    if (count($parts) == 1) {
      $config
        ->set($key, $yml[$value]);
    }
    else {
      $value = NestedArray::getValue($yml, $parts);
      $config
        ->set($key, $value);
    }
  }
  $config
    ->save(TRUE);
}