You are here

function lightning_api_update_8300 in Lightning API 8.3

Same name and namespace in other branches
  1. 8.4 lightning_api.install \lightning_api_update_8300()
  2. 8.2 lightning_api.install \lightning_api_update_8300()

Update and install OpenAPI modules.

Installs the new versions of 'ReDoc for OpenAPI UI' and 'Swagger UI for OpenAPI UI' modules, and removes the old ones. This is needed, because the corresponding openapi update hook only installs them if the old versions are enabled.

See also

openapi_update_8100

File

./lightning_api.install, line 73
Install, update, and uninstall functions for the Lightning API module.

Code

function lightning_api_update_8300() {

  /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
  $module_installer = \Drupal::service('module_installer');
  $uninstalled = $module_installer
    ->uninstall([
    'openapi_redoc',
    'openapi_swagger_ui',
  ]);

  // If the uninstall failed -- for example, the openapi_redoc and
  // openapi_swagger_ui modules were physically unavailable, as they would be if
  // they were brought in by Composer back when they were all part of the
  // openapi project before beta2 -- we need to forcibly remove them from the
  // core.extension config so that they are actually uninstalled.
  if (!$uninstalled) {
    \Drupal::configFactory()
      ->getEditable('core.extension')
      ->clear('module.openapi_redoc')
      ->clear('module.openapi_swagger_ui')
      ->save();
    Drupal::keyValue('system.schema')
      ->deleteMultiple([
      'openapi_redoc',
      'openapi_swagger_ui',
    ]);
  }
  $module_installer
    ->install([
    'openapi_ui_swagger',
    'openapi_ui_redoc',
  ]);
}