function lightning_api_entity_operation in Lightning API 8
Same name and namespace in other branches
- 8.4 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 72
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()));
$operations['api-documentation'] = [
'title' => t('View API documentation'),
'url' => Url::fromRoute('openapi_redoc.jsonapi', [], [
'fragment' => $fragment,
]),
'weight' => 51,
];
}
return $operations;
}