Create yufu_admin module and add view jsonapi output operation to nodes.
parent
507c430a48
commit
8796997a37
|
@ -47,6 +47,7 @@ module:
|
|||
update: 0
|
||||
user: 0
|
||||
views_ui: 0
|
||||
yufu_admin: 0
|
||||
content_translation: 10
|
||||
views: 10
|
||||
minimal: 1000
|
||||
|
|
|
@ -4,6 +4,7 @@ status: true
|
|||
dependencies:
|
||||
module:
|
||||
- system
|
||||
- yufu_admin
|
||||
_core:
|
||||
default_config_hash: dJ0L2DNSj5q6XVZAGsuVDpJTh5UeYkIPwKrUOOpr8YI
|
||||
id: authenticated
|
||||
|
@ -12,3 +13,4 @@ weight: 1
|
|||
is_admin: false
|
||||
permissions:
|
||||
- 'access content'
|
||||
- 'use jsonapi operation link'
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
name: Yufu Admin
|
||||
type: module
|
||||
description: Provides admin functionality.
|
||||
package: Yufu
|
||||
core_version_requirement: ^9 || ^10
|
|
@ -0,0 +1,30 @@
|
|||
<?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;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
'use jsonapi operation link':
|
||||
title: 'Use jsonapi operation link'
|
||||
description: 'Access jsonapi operation link.'
|
Loading…
Reference in New Issue