You are here

function avatars_robohash_update_8001 in Avatar Kit 8

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

File

avatars_robohash/avatars_robohash.install, line 11
Install, update and uninstall functions for Robohash module.

Code

function avatars_robohash_update_8001() {
  $plugin_ids = [
    // Old plugin ID => 'type' in plugin settings.
    'robohash_monsters' => 'monsters',
    'robohash_robot_heads' => 'robot_heads',
    'robohash_robots' => 'robots',
  ];
  $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', 'robohash')
        ->set('provider', 'avatars_robohash')
        ->set('settings', [
        'type' => $plugin_ids[$old_plugin_id],
        'background' => 'transparent',
      ])
        ->save();
    }
  }
}