function lightning_api_entity_operation in Lightning API 8.4
Same name and namespace in other branches
- 8 lightning_api.module \lightning_api_entity_operation()
- 8.2 lightning_api.module \lightning_api_entity_operation()
- 8.3 lightning_api.module \lightning_api_entity_operation()
Implements hook_entity_operation().
File
- ./
lightning_api.module, line 88 - Contains hook implementations for Lightning API.
Code
function lightning_api_entity_operation(EntityInterface $entity) {
$operations = [];
$url = lightning_api_entity_json($entity);
if ($url) {
$operations['view-json'] = [
'title' => t('View JSON'),
'url' => $url,
'weight' => 50,
];
}
$bundle_of = $entity
->getEntityType()
->getBundleOf();
if ($bundle_of && \Drupal::config('lightning_api.settings')
->get('bundle_docs')) {
$fragment = str_replace(' ', '-', sprintf('tag/%s-%s', \Drupal::entityTypeManager()
->getDefinition($bundle_of)
->getLabel(), $entity
->label()));
$route_parameters = [
'openapi_ui' => 'redoc',
'openapi_generator' => 'jsonapi',
];
$operations['api-documentation'] = [
'title' => t('View API documentation'),
'url' => Url::fromRoute('openapi.documentation', $route_parameters, [
'fragment' => $fragment,
]),
'weight' => 51,
];
}
return $operations;
}