You are here

function _opigno_lms_apply_update in Opigno LMS 3.x

Configs update helper function.

7 calls to _opigno_lms_apply_update()
opigno_lms_update_9002 in ./opigno_lms.install
Import Aristotle theme configs.
opigno_lms_update_9005 in ./opigno_lms.install
Import updated configs.
opigno_lms_update_9006 in ./opigno_lms.install
Remove the platon block and deprecated dashboard.
opigno_lms_update_9007 in ./opigno_lms.install
Update dashboard settings.
opigno_lms_update_9008 in ./opigno_lms.install
Update module configs.

... See full list

File

./opigno_lms.install, line 305
Install, update and uninstall functions for the "opigno_lms" installation profile.

Code

function _opigno_lms_apply_update($type, $name, $path, $ymls) {
  $theme_path = sprintf("%s/%s/", drupal_get_path($type, $name), $path);
  $config_factory = \Drupal::configFactory();
  $config_storage = \Drupal::service('config.storage');
  $configs = [];
  foreach ($ymls as $yml) {
    $configs[$yml] = $theme_path;
  }
  foreach ($configs as $config => $config_path) {
    $source = new FileStorage($config_path);
    $data = $source
      ->read($config);
    if (is_array($data)) {
      $config_factory
        ->getEditable($config)
        ->setData($data)
        ->save(TRUE);
      $config_storage
        ->write($config, $data);
    }
    else {
      \Drupal::messenger()
        ->addWarning(t('Incorrect data of @config', [
        '@config' => $config,
      ]));
    }
  }
}