c26be61407416c52382a617a500dd630993cc20b
[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\user\RoleInterface;
10 use Drupal\shortcut\Entity\Shortcut;
11
12 /**
13  * Implements hook_requirements().
14  */
15 function demo_umami_requirements($phase) {
16   $requirements = [];
17   if ($phase == 'runtime') {
18     $profile = \Drupal::installProfile();
19     $info = system_get_info('module', $profile);
20     $requirements['experimental_profile_used'] = [
21       'title' => t('Experimental installation profile used'),
22       'value' => $info['name'],
23       '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.'),
24       'severity' => REQUIREMENT_WARNING,
25     ];
26   }
27   return $requirements;
28 }
29
30 /**
31  * Implements hook_install().
32  *
33  * Perform actions to set up the site for this profile.
34  *
35  * @see system_install()
36  */
37 function demo_umami_install() {
38   // Set front page to "node".
39   \Drupal::configFactory()->getEditable('system.site')->set('page.front', '/node')->save(TRUE);
40
41   // Allow visitor account creation with administrative approval.
42   $user_settings = \Drupal::configFactory()->getEditable('user.settings');
43   $user_settings->set('register', USER_REGISTER_ADMINISTRATORS_ONLY)->save(TRUE);
44
45   // Assign user 1 the "administrator" role.
46   $user = User::load(1);
47   $user->roles[] = 'administrator';
48   $user->save();
49
50   // We install some menu links, so we have to rebuild the router, to ensure the
51   // menu links are valid.
52   \Drupal::service('router.builder')->rebuildIfNeeded();
53
54   // Enable the Contact link in the footer menu.
55   /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
56   $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
57   $menu_link_manager->updateDefinition('contact.site_page', ['enabled' => TRUE]);
58
59   user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access site-wide contact form']);
60   user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access site-wide contact form']);
61
62   // Allow authenticated users to use shortcuts.
63   user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access shortcuts']);
64
65   // Populate the default shortcut set.
66   $shortcut = Shortcut::create([
67     'shortcut_set' => 'default',
68     'title' => t('Add content'),
69     'weight' => -20,
70     'link' => ['uri' => 'internal:/node/add'],
71   ]);
72   $shortcut->save();
73
74   $shortcut = Shortcut::create([
75     'shortcut_set' => 'default',
76     'title' => t('All content'),
77     'weight' => -19,
78     'link' => ['uri' => 'internal:/admin/content'],
79   ]);
80   $shortcut->save();
81
82   // Allow all users to use search.
83   user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['search content']);
84   user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['search content']);
85
86   // Enable the admin theme.
87   \Drupal::configFactory()->getEditable('node.settings')->set('use_admin_theme', TRUE)->save(TRUE);
88
89   // Enable the demo content module. This can't be specified as a dependency
90   // in the demo_umami.info.yml file, as it requires configuration provided by
91   // the profile (fields etc.).
92   \Drupal::service('module_installer')->install(['demo_umami_content'], TRUE);
93 }