Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jsonapi_node_preview_tab
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
jsonapi_node_preview_tab
Commits
e6369e43
Commit
e6369e43
authored
1 year ago
by
Martin Anderson-Clutz
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3359067
by mandclu: Add a node operation
parent
5747b829
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!5
Issue #3359067: Add a node operation
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
jsonapi_node_preview_tab.links.task.yml
+1
-1
1 addition, 1 deletion
jsonapi_node_preview_tab.links.task.yml
jsonapi_node_preview_tab.module
+37
-3
37 additions, 3 deletions
jsonapi_node_preview_tab.module
jsonapi_node_preview_tab.routing.yml
+2
-2
2 additions, 2 deletions
jsonapi_node_preview_tab.routing.yml
with
40 additions
and
6 deletions
jsonapi_node_preview_tab.links.task.yml
+
1
−
1
View file @
e6369e43
jsonapi_node_preview_tab.preview
:
route_name
:
jsonapi_node_preview_tab.
preview
route_name
:
entity.node.json_
preview
title
:
'
JSON:API'
base_route
:
entity.node.canonical
weight
:
100
This diff is collapsed.
Click to expand it.
jsonapi_node_preview_tab.module
+
37
−
3
View file @
e6369e43
...
...
@@ -3,8 +3,42 @@
/**
* @file
* Primary module hooks for JSON:API Node Preview Tab module.
*/
use
Drupal\Core\Entity\EntityInterface
;
/**
* Implements hook_entity_type_build().
*/
function
jsonapi_node_preview_tab_entity_type_build
(
array
&
$entity_types
)
{
// @todo make this work for other entity types?
$entity_type_id
=
'node'
;
$entity_types
[
$entity_type_id
]
->
setLinkTemplate
(
'json-preview'
,
"/
$entity_type_id
/
{
{$entity_type_id}
}
/json-preview"
);
}
/**
* Declares entity operations.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity on which the linked operations will be performed.
*
* @return array
* An operations array as returned by
* EntityListBuilderInterface::getOperations().
*
* @DCG
* This file is no longer required in Drupal 8.
* @see https://www.drupal.org/node/2217931
* @see \Drupal\Core\Entity\EntityListBuilderInterface::getOperations()
*/
function
jsonapi_node_preview_tab_entity_operation
(
EntityInterface
$entity
)
{
if
(
$entity
->
hasLinkTemplate
(
'json-preview'
))
{
if
(
!
\Drupal
::
currentUser
()
->
hasPermission
(
'access jsonapi preview tab'
))
{
return
;
}
return
[
'json'
=>
[
'title'
=>
t
(
'JSON'
),
'weight'
=>
50
,
'url'
=>
$entity
->
toUrl
(
'json-preview'
),
],
];
}
}
This diff is collapsed.
Click to expand it.
jsonapi_node_preview_tab.routing.yml
+
2
−
2
View file @
e6369e43
jsonapi_node_preview_tab.
preview
:
entity.node.json_
preview
:
path
:
'
/node/{node}/json-preview'
defaults
:
_title_callback
:
'
\Drupal\jsonapi_node_preview_tab\Controller\JsonapiNodePreviewTabController::getTitle'
_controller
:
'
\Drupal\jsonapi_node_preview_tab\Controller\JsonapiNodePreviewTabController::build'
requirements
:
_permission
:
'
access
jsonapi
preview
tab'
# node: \d+
options
:
_node_operation_route
:
TRUE
parameters
:
node
:
type
:
entity:node
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment