You are here

function avatars_gravatar_update_8001 in Avatar Kit 8

Migrate plugins with old plugin IDs to new plugin IDs and settings.

File

avatars_gravatar/avatars_gravatar.install, line 11
Install, update and uninstall functions for Gravatar module.

Code

function avatars_gravatar_update_8001() {
  $plugin_ids = [
    // Old plugin ID => 'type' in plugin settings.
    'gravatar_identicon' => 'identicon',
    'gravatar_monsterid' => 'monsterid',
    'gravatar_wavatar' => 'wavatar',
    'gravatar_retro' => 'retro',
  ];
  $config_factory = \Drupal::configFactory();
  foreach ($config_factory
    ->listAll('avatars.generator.') as $config_id) {
    $config = $config_factory
      ->getEditable($config_id);
    $old_plugin_id = $config
      ->get('plugin');
    if ($old_plugin_id && isset($plugin_ids[$old_plugin_id])) {
      $config
        ->set('plugin', 'gravatar_generator')
        ->set('provider', 'avatars_gravatar')
        ->set('settings', [
        'type' => $plugin_ids[$old_plugin_id],
      ])
        ->save();
    }
  }
}