-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreasonable_graph.install
More file actions
87 lines (77 loc) · 2.24 KB
/
reasonable_graph.install
File metadata and controls
87 lines (77 loc) · 2.24 KB
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
81
82
83
84
85
86
87
<?php
use Drupal\system\Entity\Menu;
/**
* @file
* Install, update and uninstall functions for the Reasonable Graph module.
*/
/**
* Implements hook_install().
*/
function reasonable_graph_install() {
// Load the entity type manager.
$entity_type_manager = \Drupal::entityTypeManager();
// Check if the menu already exists.
if (!$entity_type_manager->getStorage('menu')->load('rg_menu')) {
// Create a new custom menu.
$menu = $entity_type_manager->getStorage('menu')->create([
'id' => 'rg_menu',
'label' => 'Reasonable Graph Menu',
'description' => 'Reasonable Graph basic links menu',
]);
$menu->save();
}
// Add custom menu links.
$menu_link_storage = $entity_type_manager->getStorage('menu_link_content');
// Define the menu links.
$links = [
[
'title' => 'Cataloging',
'link' => ['uri' => 'internal:/prepo/cataloging'],
'weight' => 0,
'options' => ['attributes' => ['class' => ['link-cataloging']]],
],
[
'title' => 'Admin Panel',
'link' => ['uri' => 'internal:/prepo/menu'],
'weight' => 10,
'options' => [
'attributes' => ['class' => ['link-prepo-menu']],
'access arguments' => ['acl_repo_admin'], // ✅ Restrict by permission
],
],
[
'title' => 'Search',
'link' => ['uri' => 'internal:/archive/search'],
'weight' => -10, // Lower weight → higher priority
'options' => ['attributes' => ['class' => ['link-archive-search']]],
],
];
// Add links to the menu.
foreach ($links as $link) {
$menu_link = $menu_link_storage->create([
'title' => $link['title'],
'link' => $link['link'],
'menu_name' => 'rg_menu',
'weight' => $link['weight'],
'enabled' => TRUE,
'options' => $link['options'],
]);
$menu_link->save();
}
}
/**
* Implements hook_uninstall().
*/
function reasonable_graph_uninstall() {
// Remove all menu links associated with rg_menu.
$menu_links = \Drupal::entityTypeManager()
->getStorage('menu_link_content')
->loadByProperties(['menu_name' => 'rg_menu']);
foreach ($menu_links as $menu_link) {
$menu_link->delete();
}
// Remove the menu itself.
if ($menu = Menu::load('rg_menu')) {
$menu->delete();
}
}