Skip to content
Snippets Groups Projects
Commit e6369e43 authored by Martin Anderson-Clutz's avatar Martin Anderson-Clutz
Browse files

Issue #3359067 by mandclu: Add a node operation

parent 5747b829
No related branches found
No related tags found
1 merge request!5Issue #3359067: Add a node operation
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
......@@ -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'),
],
];
}
}
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment