You are here

private function ConfigImportEventSubscriber::saveConfigFileFromState in Config Ignore Keys 8

Fetches the state variable defined by key/file and saves it.

Parameters

string $configFile: The config file name.

string $configKey: The configuration key which needs to be ignored.

1 call to ConfigImportEventSubscriber::saveConfigFileFromState()
ConfigImportEventSubscriber::onConfigImport in src/EventSubscriber/ConfigImportEventSubscriber.php
Saves the old configuration for the ignored config keys.

File

src/EventSubscriber/ConfigImportEventSubscriber.php, line 201

Class

ConfigImportEventSubscriber
Class ConfigImportEventSubscriber.

Namespace

Drupal\config_ignore_keys\EventSubscriber

Code

private function saveConfigFileFromState($configFile, $configKey) {
  foreach ($this->languageManager
    ->getLanguages() as $language) {
    $stateValue = $stateValue = $this->state
      ->get($language
      ->getId() . $configFile . $configKey);
    if (isset($stateValue)) {
      $config_translation = $this->languageConfigFactoryOverride
        ->getOverride($language
        ->getId(), $configFile);
      $config_translation
        ->setData($stateValue);
      $config_translation
        ->save();
    }
  }
  $stateValue = $this->state
    ->get($configFile . $configKey);
  if (isset($stateValue)) {
    $config = $this->configFactory
      ->getEditable($configFile);
    if (!empty($config)) {
      $config
        ->setData($stateValue);
      $config
        ->save();
    }
  }
}