Version 1
[yaffs-website] / web / core / profiles / standard / standard.install
1 <?php
2
3 /**
4  * @file
5  * Install, update and uninstall functions for the standard 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_install().
14  *
15  * Perform actions to set up the site for this profile.
16  *
17  * @see system_install()
18  */
19 function standard_install() {
20   // Set front page to "node".
21   \Drupal::configFactory()->getEditable('system.site')->set('page.front', '/node')->save(TRUE);
22
23   // Allow visitor account creation with administrative approval.
24   $user_settings = \Drupal::configFactory()->getEditable('user.settings');
25   $user_settings->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save(TRUE);
26
27   // Enable default permissions for system roles.
28   user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']);
29   user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access comments', 'post comments', 'skip comment approval']);
30
31   // Assign user 1 the "administrator" role.
32   $user = User::load(1);
33   $user->roles[] = 'administrator';
34   $user->save();
35
36   // We install some menu links, so we have to rebuild the router, to ensure the
37   // menu links are valid.
38   \Drupal::service('router.builder')->rebuildIfNeeded();
39
40   // Enable the Contact link in the footer menu.
41   /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
42   $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
43   $menu_link_manager->updateDefinition('contact.site_page', ['enabled' => TRUE]);
44
45   user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access site-wide contact form']);
46   user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access site-wide contact form']);
47
48   // Allow authenticated users to use shortcuts.
49   user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access shortcuts']);
50
51   // Populate the default shortcut set.
52   $shortcut = Shortcut::create([
53     'shortcut_set' => 'default',
54     'title' => t('Add content'),
55     'weight' => -20,
56     'link' => ['uri' => 'internal:/node/add'],
57   ]);
58   $shortcut->save();
59
60   $shortcut = Shortcut::create([
61     'shortcut_set' => 'default',
62     'title' => t('All content'),
63     'weight' => -19,
64     'link' => ['uri' => 'internal:/admin/content'],
65   ]);
66   $shortcut->save();
67
68   // Allow all users to use search.
69   user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['search content']);
70   user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['search content']);
71
72   // Enable the admin theme.
73   \Drupal::configFactory()->getEditable('node.settings')->set('use_admin_theme', TRUE)->save(TRUE);
74 }