5 * Install, update and uninstall functions for the standard installation profile.
8 use Drupal\user\Entity\User;
9 use Drupal\user\RoleInterface;
10 use Drupal\shortcut\Entity\Shortcut;
13 * Implements hook_install().
15 * Perform actions to set up the site for this profile.
17 * @see system_install()
19 function standard_install() {
20 // Set front page to "node".
21 \Drupal::configFactory()->getEditable('system.site')->set('page.front', '/node')->save(TRUE);
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);
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']);
31 // Assign user 1 the "administrator" role.
32 $user = User::load(1);
33 $user->roles[] = 'administrator';
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();
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]);
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']);
48 // Allow authenticated users to use shortcuts.
49 user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access shortcuts']);
51 // Populate the default shortcut set.
52 $shortcut = Shortcut::create([
53 'shortcut_set' => 'default',
54 'title' => t('Add content'),
56 'link' => ['uri' => 'internal:/node/add'],
60 $shortcut = Shortcut::create([
61 'shortcut_set' => 'default',
62 'title' => t('All content'),
64 'link' => ['uri' => 'internal:/admin/content'],
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']);
72 // Enable the admin theme.
73 \Drupal::configFactory()->getEditable('node.settings')->set('use_admin_theme', TRUE)->save(TRUE);