function geocoder_post_update_convert_simple_config_to_entities in Geocoder 8.3
Convert simple provider configuration to provider entities.
File
- ./
geocoder.post_update.php, line 16
Code
function geocoder_post_update_convert_simple_config_to_entities() : void {
// Ensure the new GeocoderProvider entity type is available.
\Drupal::entityTypeManager()
->clearCachedDefinitions();
$config_factory = \Drupal::configFactory();
$config = $config_factory
->getEditable('geocoder.settings');
$plugin_definitions = \Drupal::service('plugin.manager.geocoder.provider')
->getDefinitions();
foreach ($config
->get('plugins_options') as $plugin_id => $configuration) {
if (!isset($plugin_definitions[$plugin_id])) {
continue;
}
// Change key case to match the new version.
$configuration['apiKey'] = $configuration['apikey'];
unset($configuration['apikey']);
try {
GeocoderProvider::create([
'id' => $plugin_id,
'label' => $plugin_definitions[$plugin_id]['name'],
'plugin' => $plugin_id,
'configuration' => $configuration,
])
->save();
} catch (EntityStorageException $e) {
watchdog_exception('geocoder_provider', $e);
}
}
$config
->clear('plugins_options');
$config
->save();
}