Chris@14
|
1 <?php
|
Chris@14
|
2
|
Chris@14
|
3 /**
|
Chris@14
|
4 * @file
|
Chris@14
|
5 * Install, update and uninstall functions for the demo_umami installation profile.
|
Chris@14
|
6 */
|
Chris@14
|
7
|
Chris@14
|
8 use Drupal\user\Entity\User;
|
Chris@14
|
9 use Drupal\shortcut\Entity\Shortcut;
|
Chris@14
|
10
|
Chris@14
|
11 /**
|
Chris@14
|
12 * Implements hook_requirements().
|
Chris@14
|
13 */
|
Chris@14
|
14 function demo_umami_requirements($phase) {
|
Chris@14
|
15 $requirements = [];
|
Chris@14
|
16 if ($phase == 'runtime') {
|
Chris@14
|
17 $profile = \Drupal::installProfile();
|
Chris@14
|
18 $info = system_get_info('module', $profile);
|
Chris@14
|
19 $requirements['experimental_profile_used'] = [
|
Chris@14
|
20 'title' => t('Experimental installation profile used'),
|
Chris@14
|
21 'value' => $info['name'],
|
Chris@14
|
22 'description' => t('Experimental profiles are provided for testing purposes only. Use at your own risk. To start building a new site, reinstall Drupal and choose a non-experimental profile.'),
|
Chris@14
|
23 'severity' => REQUIREMENT_WARNING,
|
Chris@14
|
24 ];
|
Chris@14
|
25 }
|
Chris@14
|
26 return $requirements;
|
Chris@14
|
27 }
|
Chris@14
|
28
|
Chris@14
|
29 /**
|
Chris@14
|
30 * Implements hook_install().
|
Chris@14
|
31 *
|
Chris@14
|
32 * Perform actions to set up the site for this profile.
|
Chris@14
|
33 *
|
Chris@14
|
34 * @see system_install()
|
Chris@14
|
35 */
|
Chris@14
|
36 function demo_umami_install() {
|
Chris@14
|
37 // Assign user 1 the "administrator" role.
|
Chris@14
|
38 $user = User::load(1);
|
Chris@14
|
39 $user->roles[] = 'administrator';
|
Chris@14
|
40 $user->save();
|
Chris@14
|
41
|
Chris@14
|
42 // We install some menu links, so we have to rebuild the router, to ensure the
|
Chris@14
|
43 // menu links are valid.
|
Chris@14
|
44 \Drupal::service('router.builder')->rebuildIfNeeded();
|
Chris@14
|
45
|
Chris@14
|
46 // Populate the default shortcut set.
|
Chris@14
|
47 $shortcut = Shortcut::create([
|
Chris@14
|
48 'shortcut_set' => 'default',
|
Chris@14
|
49 'title' => t('Add content'),
|
Chris@14
|
50 'weight' => -20,
|
Chris@14
|
51 'link' => ['uri' => 'internal:/node/add'],
|
Chris@14
|
52 ]);
|
Chris@14
|
53 $shortcut->save();
|
Chris@14
|
54
|
Chris@14
|
55 $shortcut = Shortcut::create([
|
Chris@14
|
56 'shortcut_set' => 'default',
|
Chris@14
|
57 'title' => t('All content'),
|
Chris@14
|
58 'weight' => -19,
|
Chris@14
|
59 'link' => ['uri' => 'internal:/admin/content'],
|
Chris@14
|
60 ]);
|
Chris@14
|
61 $shortcut->save();
|
Chris@14
|
62
|
Chris@14
|
63 // Enable the demo content module. This can't be specified as a dependency
|
Chris@14
|
64 // in the demo_umami.info.yml file, as it requires configuration provided by
|
Chris@14
|
65 // the profile (fields etc.).
|
Chris@14
|
66 \Drupal::service('module_installer')->install(['demo_umami_content'], TRUE);
|
Chris@14
|
67 }
|