|
8 | 8 | use Drupal\shortcut\Entity\Shortcut; |
9 | 9 | use Drupal\menu_link_content\Entity\MenuLinkContent; |
10 | 10 |
|
11 | | -// Define a default theme constant. |
12 | | -const GOVCMS_DEFAULT_THEME = 'govcms_bartik'; |
13 | | - |
14 | | -// Define the admin theme. |
15 | | -const GOVCMS_DEFAULT_ADMIN_THEME = 'claro'; |
16 | | - |
17 | 11 | // GovCMS update hooks. |
18 | 12 | include_once __DIR__ . '/includes/govcms.update.inc'; |
19 | 13 |
|
20 | 14 | /** |
21 | 15 | * Implements hook_install(). |
22 | 16 | * |
23 | | - * Perform actions to set up the site for GovCMS Profile. |
| 17 | + * Sets up the GovCMS profile during installation. |
24 | 18 | * |
25 | 19 | * @see system_install() |
26 | 20 | */ |
27 | 21 | function govcms_install() { |
28 | | - // Restrict user registration to admin role creation. |
29 | | - \Drupal::configFactory() |
30 | | - ->getEditable('user.settings') |
31 | | - ->set('register', \Drupal\user\UserInterface::REGISTER_ADMINISTRATORS_ONLY) |
32 | | - ->save(TRUE); |
33 | | - |
34 | | - // Populate the default shortcut set. |
35 | | - Shortcut::create( |
36 | | - [ |
37 | | - 'shortcut_set' => 'default', |
38 | | - 'title' => t('Add content'), |
39 | | - 'weight' => 1, |
40 | | - 'link' => ['uri' => 'internal:/node/add'], |
41 | | - ] |
42 | | - )->save(); |
| 22 | + // Create default shortcut for adding content. |
| 23 | + Shortcut::create([ |
| 24 | + 'shortcut_set' => 'default', |
| 25 | + 'title' => t('Add content'), |
| 26 | + 'weight' => 1, |
| 27 | + 'link' => ['uri' => 'internal:/node/add'], |
| 28 | + ])->save(); |
43 | 29 |
|
44 | | - MenuLinkContent::create( |
45 | | - [ |
46 | | - 'title' => 'Accessibility', |
| 30 | + // Create footer menu links. |
| 31 | + $footerMenuLinks = ['Accessibility', 'Copyright', 'Disclaimers', 'Privacy']; |
| 32 | + foreach ($footerMenuLinks as $linkTitle) { |
| 33 | + MenuLinkContent::create([ |
| 34 | + 'title' => $linkTitle, |
47 | 35 | 'link' => ['uri' => 'https://www.govcms.gov.au'], |
48 | 36 | 'menu_name' => 'footer', |
49 | | - ] |
50 | | - )->save(); |
| 37 | + ])->save(); |
| 38 | + } |
51 | 39 |
|
52 | | - MenuLinkContent::create( |
| 40 | + // Create custom menu links. |
| 41 | + $customMenuLinks = [ |
53 | 42 | [ |
54 | | - 'title' => 'Copyright', |
55 | | - 'link' => ['uri' => 'https://www.govcms.gov.au'], |
56 | | - 'menu_name' => 'footer', |
57 | | - ] |
58 | | - )->save(); |
59 | | - |
60 | | - MenuLinkContent::create( |
| 43 | + 'title' => 'Our community', |
| 44 | + 'path' => '/our-community', |
| 45 | + 'menu_name' => 'govcms-community', |
| 46 | + ], |
61 | 47 | [ |
62 | | - 'title' => 'Disclaimers', |
63 | | - 'link' => ['uri' => 'https://www.govcms.gov.au'], |
64 | | - 'menu_name' => 'footer', |
65 | | - ] |
66 | | - )->save(); |
67 | | - |
68 | | - MenuLinkContent::create( |
69 | | - [ |
70 | | - 'title' => 'Privacy', |
71 | | - 'link' => ['uri' => 'https://www.govcms.gov.au'], |
72 | | - 'menu_name' => 'footer', |
73 | | - ] |
74 | | - )->save(); |
75 | | - |
76 | | - MenuLinkContent::create([ |
77 | | - 'title' => 'Our community', |
78 | | - 'link' => ['uri' => 'https://www.govcms.gov.au/our-community'], |
79 | | - 'menu_name' => 'govcms-community', |
80 | | - ])->save(); |
81 | | - |
82 | | - MenuLinkContent::create([ |
83 | | - 'title' => 'About GovCMS', |
84 | | - 'link' => ['uri' => 'https://www.govcms.gov.au/about'], |
85 | | - 'menu_name' => 'govcms-about', |
86 | | - ])->save(); |
| 48 | + 'title' => 'About GovCMS', |
| 49 | + 'path' => '/about', |
| 50 | + 'menu_name' => 'govcms-about', |
| 51 | + ], |
| 52 | + ]; |
| 53 | + foreach ($customMenuLinks as $customLink) { |
| 54 | + MenuLinkContent::create([ |
| 55 | + 'title' => $customLink['title'], |
| 56 | + 'link' => ['uri' => 'https://www.govcms.gov.au' . $customLink['path']], |
| 57 | + 'menu_name' => $customLink['menu_name'], |
| 58 | + ])->save(); |
| 59 | + } |
87 | 60 |
|
88 | | - // Don't do anything else during config sync. |
| 61 | + // Skip further actions during config sync. |
89 | 62 | if (\Drupal::isConfigSyncing()) { |
90 | 63 | return; |
91 | 64 | } |
92 | 65 |
|
93 | 66 | // Set front page to "node". |
| 67 | + $frontPagePath = '/node'; |
94 | 68 | \Drupal::configFactory() |
95 | 69 | ->getEditable('system.site') |
96 | | - ->set('page.front', '/node') |
97 | | - ->save(TRUE); |
98 | | - |
99 | | - // Set the default and admin theme. |
100 | | - \Drupal::configFactory() |
101 | | - ->getEditable('system.theme') |
102 | | - ->set('default', GOVCMS_DEFAULT_THEME) |
103 | | - ->set('admin', GOVCMS_DEFAULT_ADMIN_THEME) |
104 | | - ->save(TRUE); |
105 | | - |
106 | | - // Enable the admin theme. |
107 | | - \Drupal::configFactory() |
108 | | - ->getEditable('node.settings') |
109 | | - ->set('use_admin_theme', TRUE) |
| 70 | + ->set('page.front', $frontPagePath) |
110 | 71 | ->save(TRUE); |
111 | 72 |
|
112 | | - // Set the path to the logo, favicon and README file based on install directory. |
113 | | - $govcms_path = \Drupal::service('extension.list.profile')->getPath('govcms'); |
| 73 | + // Set paths for the logo, favicon, and README file based on install directory. |
| 74 | + $govcmsPath = \Drupal::service('extension.list.profile')->getPath('govcms'); |
114 | 75 | \Drupal::configFactory() |
115 | 76 | ->getEditable('system.theme.global') |
116 | 77 | ->set('logo', [ |
117 | | - 'path' => $govcms_path . '/logo.svg', |
| 78 | + 'path' => $govcmsPath . '/logo.svg', |
118 | 79 | 'url' => '', |
119 | 80 | 'use_default' => TRUE, |
120 | 81 | ]) |
121 | 82 | ->set('favicon', [ |
122 | 83 | 'mimetype' => 'image/vnd.microsoft.icon', |
123 | | - 'path' => $govcms_path . '/favicon.ico', |
| 84 | + 'path' => $govcmsPath . '/favicon.ico', |
124 | 85 | 'url' => '', |
125 | 86 | 'use_default' => FALSE, |
126 | 87 | ]) |
127 | 88 | ->save(TRUE); |
128 | 89 |
|
129 | | - // Grant the default permissions. |
| 90 | + // Grant default permissions. |
130 | 91 | govcms_default_permissions(); |
131 | 92 | } |
0 commit comments