function dropzonejs_eb_widget_update_8201 in DropzoneJS 8.2
Update configurations for configuration key renaming.
File
- modules/
eb_widget/ dropzonejs_eb_widget.install, line 27 - Install function hooks for the DropzoneJS entity browser widget module.
Code
function dropzonejs_eb_widget_update_8201() {
$logger = \Drupal::logger('dropzonejs');
/** @var \Drupal\entity_browser\Entity\EntityBrowser[] $entity_browsers */
$entity_browsers = EntityBrowser::loadMultiple();
foreach ($entity_browsers as $entity_browser) {
/** @var \Drupal\entity_browser\WidgetInterface[] $widgets */
$widgets = $entity_browser
->getWidgets();
$entity_browser_config = \Drupal::configFactory()
->getEditable('entity_browser.browser.' . $entity_browser
->id());
$has_config_changes = FALSE;
foreach ($widgets as $widget) {
if ($widget instanceof MediaEntityDropzoneJsEbWidget) {
$config = $widget
->getConfiguration();
if (!empty($config['settings']['media_entity_bundle']) && empty($config['settings']['media_type'])) {
$has_config_changes = TRUE;
$widget_id = $widget
->getConfiguration()['uuid'];
$value = $entity_browser_config
->get('widgets.' . $widget_id . '.settings.media_entity_bundle');
$entity_browser_config
->set('widgets.' . $widget_id . '.settings.media_type', $value);
$entity_browser_config
->clear('widgets.' . $widget_id . '.settings.media_entity_bundle');
$logger
->info(sprintf('Configuration changed for widget (%s) of entity browser (%s)', $widget
->label(), $entity_browser
->label()));
}
else {
$logger
->warning(sprintf('Unable to change configuration for widget (%s) of entity browser (%s)', $widget
->label(), $entity_browser
->label()));
}
}
}
if ($has_config_changes) {
$entity_browser_config
->save();
}
}
}