function lightning_api_install in Lightning API 8.2
Same name and namespace in other branches
- 8.4 lightning_api.install \lightning_api_install()
- 8 lightning_api.install \lightning_api_install()
- 8.3 lightning_api.install \lightning_api_install()
Implements hook_install().
File
- ./
lightning_api.install, line 9
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\Core\Path\AliasStorageInterface $alias_storage */
$alias_storage = \Drupal::service('path.alias_storage');
$path = $alias_storage
->lookupPathSource('/api-docs', LanguageInterface::LANGCODE_NOT_SPECIFIED);
if (empty($path)) {
$route_parameters = [
'openapi_ui' => 'redoc',
'openapi_generator' => 'jsonapi',
];
$alias_storage
->save(Url::fromRoute('openapi.docs', $route_parameters)
->toString(), '/api-docs');
}
}
}