You are here

function avatars_update_8001 in Avatar Kit 8

Migrate list of enabled avatar generators to plugin configs.

File

./avatars.install, line 104
Install, update and uninstall functions for the AK module.

Code

function avatars_update_8001() {
  $config_factory = \Drupal::configFactory();

  // A list of avatar generator plugin ID's ordered by weight.
  $avatar_settings = $config_factory
    ->getEditable('avatars.settings');
  $avatar_generators = $avatar_settings
    ->get('avatar_generators');
  if (is_array($avatar_generators)) {
    foreach ($avatar_generators as $weight => $avatar_generator) {
      $avatar_generator = $avatar_generator == '_user_preference' ? 'user_preference' : $avatar_generator;
      $config_factory
        ->getEditable('avatars.generator.' . $avatar_generator)
        ->setData([
        'id' => $avatar_generator,
        'label' => $avatar_generator,
        'weight' => $weight,
        'plugin' => $avatar_generator,
        'provider' => $avatar_generator,
        'settings' => [],
        'status' => TRUE,
      ])
        ->save();
    }
    $avatar_settings
      ->clear('avatar_generators')
      ->save();
  }
}