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