You are here

function lightning_api_install in Lightning API 8.4

Same name and namespace in other branches
  1. 8 lightning_api.install \lightning_api_install()
  2. 8.2 lightning_api.install \lightning_api_install()
  3. 8.3 lightning_api.install \lightning_api_install()

Implements hook_install().

File

./lightning_api.install, line 18
Contains installation and update routines for Lightning API.

Code

function lightning_api_install() {
  $module_handler = \Drupal::moduleHandler();

  // If the openapi_ui_redoc and jsonapi modules are installed, give the API
  // documentation a nice path alias.
  if ($module_handler
    ->moduleExists('openapi_ui_redoc') && $module_handler
    ->moduleExists('jsonapi')) {

    /** @var \Drupal\path_alias\AliasRepository $alias_storage */
    $alias_storage = \Drupal::service('path_alias.repository');
    $path = $alias_storage
      ->lookupByAlias('/api-docs', LanguageInterface::LANGCODE_NOT_SPECIFIED);
    if (empty($path)) {
      $route_parameters = [
        'openapi_ui' => 'redoc',
        'openapi_generator' => 'jsonapi',
      ];
      PathAlias::create([
        'path' => Url::fromRoute('openapi.documentation', $route_parameters)
          ->toString(),
        'alias' => '/api-docs',
      ])
        ->save();
    }
  }

  // Disable the content view's 'Include destination' switch.
  if (!\Drupal::isConfigSyncing()) {
    lightning_api_update_8301();
  }
}