You are here

function lockr_update_8301 in Lockr 8.4

Same name and namespace in other branches
  1. 8.3 lockr.install \lockr_update_8301()
  2. 4.x lockr.install \lockr_update_8301()

Migrate to config.

File

./lockr.install, line 6

Code

function lockr_update_8301() {
  $configFactory = \Drupal::service('config.factory');
  $state = \Drupal::service('state');
  $config = $configFactory
    ->getEditable('lockr.settings');

  // There was a patch on d.o for the 8.x-2.x branch that added support
  // for storing Lockr configuration in config. The schema is similar
  // but not exactly the same, so we modify the config object slightly.
  if (!$config
    ->get('region') && ($region = $state
    ->get('lockr.region'))) {
    $config
      ->set('region', $region);
  }
  if ($config
    ->get('custom')) {
    $config
      ->set('cert_path', $config
      ->get('custom_cert'));
    $config
      ->clear('custom_cert');
  }
  elseif ($state
    ->get('lockr.custom', FALSE)) {
    $config
      ->set('custom', TRUE);
    $config
      ->set('cert_path', $state
      ->get('lockr.cert'));
  }
  $config
    ->save();
}