-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_duplicate.module
More file actions
37 lines (30 loc) · 952 Bytes
/
node_duplicate.module
File metadata and controls
37 lines (30 loc) · 952 Bytes
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
<?php
// This operation relies on Drupal's destination handling
// in admin views to return the user to the content listing.
declare(strict_types=1);
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_entity_operation_alter().
*/
function node_duplicate_entity_operation_alter(array &$operations, EntityInterface $entity): void {
if ($entity->getEntityTypeId() !== 'node') {
return;
}
$account = \Drupal::currentUser();
$create_access = \Drupal::entityTypeManager()
->getAccessControlHandler('node')
->createAccess($entity->bundle(), $account, [], TRUE);
if (!$create_access->isAllowed()) {
return;
}
if (!$entity->access('view', $account)) {
return;
}
$operations['duplicate'] = [
'title' => t('Duplicate'),
'weight' => 25,
'url' => \Drupal\Core\Url::fromRoute('node_duplicate.duplicate', [
'node' => $entity->id(),
]),
];
}