Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Add helper function for config import
Browse files Browse the repository at this point in the history
  • Loading branch information
froboy authored Mar 10, 2022
1 parent b907ba7 commit 07ec62f
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion openy_activity_finder.install
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function openy_activity_finder_update_8402() {
/**
* Update configs for search index.
*/
function openy_activity_finder_update_8404() {
function openy_activity_finder_update_8403() {
$cim = \Drupal::service('config_import.importer');
$cim->setDirectory(drupal_get_path('module', 'openy_activity_finder') . '/config/optional');
$config = \Drupal::config('search_api.index.default');
Expand All @@ -232,3 +232,30 @@ function openy_activity_finder_update_8404() {
$cim->importConfigs(['search_api.index.default']);
}
}

/**
* Update configs for search index.
*/
function openy_activity_finder_update_8404() {
_af_config_import();
}

/**
* Update configs for search index. Configs should be sent in an array where the
* key is the directory and the value is an array of config files.
*/
function _af_config_import($import = ['optional' => ['search_api.index.default']]) {
$cim = \Drupal::service('config_import.importer');
// Loop through keys as directories...
foreach ($import as $dir => $configs) {
$cim->setDirectory(\Drupal::service('extension.list.module')->getPath('openy_activity_finder') . '/config/'. $dir);
// Now process each config to be imported.
foreach ($configs as $name) {
$config = \Drupal::config($name);
if (!$config->isNew()) {
// Import config only in the case that it already exists.
$cim->importConfigs([$name]);
}
}
}
}

0 comments on commit 07ec62f

Please sign in to comment.