lightning_api-8.x-4.x-dev/lightning_api.install
lightning_api.install
<?php
/**
* @file
* Contains installation and update routines for Lightning API.
*/
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\path_alias\Entity\PathAlias;
/**
* Implements hook_install().
*/
function lightning_api_install() {
$module_handler = \Drupal::moduleHandler();
// If the openapi_ui_redoc and openapi_jsonapi modules are installed, give the
// API documentation a nice path alias.
if ($module_handler->moduleExists('openapi_ui_redoc') && $module_handler->moduleExists('openapi_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();
}
}
}
/**
* Implements hook_update_last_removed().
*/
function lightning_api_update_last_removed(): int {
return 8402;
}
