You are here

function file_browser_update_8005 in File Entity Browser 8

Fix widget configuration if it was broken by a previous update.

File

./file_browser.install, line 238
Defines library requirements and install routines for File Browser.

Code

function file_browser_update_8005() {

  /** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
  $config_factory = \Drupal::service('config.factory');
  $list = $config_factory
    ->listAll('entity_browser.browser');
  $default_uuid = 'a4ad947c-9669-497c-9988-24351955a02f';
  foreach ([
    'entity_browser.browser.browse_files',
    'entity_browser.browser.browse_files_modal',
  ] as $name) {
    if (in_array($name, $list, TRUE)) {
      $entity_browser = $config_factory
        ->getEditable($name);
      $widgets = $entity_browser
        ->get('widgets');

      // If the UUID exists but has no plugin ID, it was added accidentally.
      if (isset($widgets[$default_uuid]) && !isset($widgets[$default_uuid]['id'])) {
        $entity_browser
          ->clear("widgets.{$default_uuid}");
        $entity_browser
          ->save();
      }
    }
  }
}