-
Notifications
You must be signed in to change notification settings - Fork 1
/
wmsingles.module
80 lines (66 loc) · 2.22 KB
/
wmsingles.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
75
76
77
78
79
80
<?php
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\node\Entity\NodeType;
use Drupal\wmsingles\Access\SingleNodeAccessControlHandler;
function wmsingles_entity_operation_alter(array &$operations, EntityInterface $entity)
{
/** @var EntityInterface|null $single */
$single = \Drupal::service('wmsingles')->getSingleByBundle($entity->bundle());
if ($entity->getEntityTypeId() !== 'node' || !$single) {
return;
}
$operations['view'] = [
'title' => t('View'),
'weight' => 5,
'url' => Url::fromRoute('entity.node.canonical', ['node' => $entity->id()]),
];
if (!empty($operations['edit'])) {
$operations['edit']['weight'] = 4;
}
if (!empty($operations['delete'])) {
$operations['delete']['weight'] = 15;
}
$nodeType = NodeType::load($entity->bundle());
$nodeTypeOperations = \Drupal::entityTypeManager()
->getListBuilder('node_type')
->getOperations($nodeType);
if (isset($nodeTypeOperations['edit'])) {
$nodeTypeOperations['edit']['title'] = t('Edit type');
$nodeTypeOperations['edit-type'] = $nodeTypeOperations['edit'];
unset($nodeTypeOperations['edit']);
}
$operations += $nodeTypeOperations;
}
function wmsingles_entity_insert(EntityInterface $entity)
{
\Drupal::getContainer()
->get('wmsingles.nodetypeupdate_subscriber')
->checkForSingles($entity);
}
function wmsingles_entity_update(EntityInterface $entity)
{
\Drupal::getContainer()
->get('wmsingles.nodetypeupdate_subscriber')
->checkForSingles($entity);
}
function wmsingles_form_node_type_form_alter(array &$form, FormStateInterface $formState)
{
\Drupal::getContainer()
->get('wmsingles.nodetypeform_subscriber')
->alterNodeTypeForm($form, $formState);
}
function wmsingles_form_node_form_alter(array &$form)
{
\Drupal::getContainer()
->get('wmsingles.nodeform_subscriber')
->formAlter($form);
}
/**
* Implements @see hook_entity_type_alter().
*/
function wmsingles_entity_type_alter(array &$entityTypes): void
{
$entityTypes['node']->setHandlerClass('access', SingleNodeAccessControlHandler::class);
}