manifest/web/modules/custom/yufu_admin/yufu_admin.module

31 lines
814 B
PHP
Raw Normal View History

<?php
/**
* @file
* Primary module hooks for Yufu Admin module.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
/**
* Implements hook_entity_operation().
*/
function yufu_admin_entity_operation(EntityInterface $entity) {
$operations = [];
$entityType = $entity->getEntityType();
// @todo Only for entity node - should we add other entities as well?
if ($entityType->id() === 'node' && \Drupal::currentUser()->hasPermission('use jsonapi operation link')) {
// Build the url.
$url = Url::fromRoute(sprintf('jsonapi.%s--%s.individual', $entityType->id(), $entity->bundle()),
['entity' => $entity->uuid()]
);
$operations['view-jsonapi-output'] = [
'title' => t('jsonapi Output'),
'weight' => 50,
'url' => $url,
];
}
return $operations;
}