This repository has been archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent_direct.module
executable file
·74 lines (69 loc) · 2.26 KB
/
content_direct.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* @file
* Content Direct module file.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
/**
* Implements hook_help().
*/
function content_direct_help($route_name) {
switch ($route_name) {
case 'content_direct.help':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('This is the help docs for Content Direct, see <a href="!content_direct-module">the online documentation</a></p>');
return $output;
}
}
/**
* Implements hook_entity_operation().
*/
function content_direct_entity_operation(EntityInterface $entity) {
$operations = array();
if (\Drupal::currentUser()->hasPermission('use_content_direct')) {
$entity_type = $entity->getEntityType()->id();
$action_routes = array(
'node' => 'content_direct.node_actions',
'file' => 'content_direct.file_actions',
);
// Add one of the action routes if one of the Entities.
if (array_key_exists($entity_type, $action_routes)) {
$operations['content_direct'] = array(
'title' => t('Content Direct'),
'weight' => 100,
'url' => Url::fromRoute($action_routes[$entity_type], array(
$entity->getEntityTypeId() => $entity->id(),
)),
);
}
// Add one of the history routes if one of the Entities.
$history_routes = array(
'node' => 'content_direct.node_history',
'file' => 'content_direct.file_history',
);
if (array_key_exists($entity_type, $history_routes)) {
$operations['content_direct_history'] = array(
'title' => t('History'),
'weight' => 100,
'url' => Url::fromRoute($history_routes[$entity_type], array(
$entity->getEntityTypeId() => $entity->id(),
)),
);
}
// @TODO: Not able to alter operations on MenuLinkContent either.
// @TODO: Not able to alter operations for taxonomy terms.
// see: Patch expected for 8.2.x https://www.drupal.org/node/2469567
/*if ($entity_type == 'taxonomy_term') {
$operations['content_direct'] = array(
'title' => t('Content Direct'),
'weight' => 100,
'url' => Url::fromRoute("content_direct.term_actions", array(
$entity->getEntityTypeId() => $entity->id(),
)),
);
}*/
}
return $operations;
}