5 * Install, update and uninstall functions for the demo_umami installation profile.
8 use Drupal\user\Entity\User;
9 use Drupal\user\RoleInterface;
10 use Drupal\shortcut\Entity\Shortcut;
13 * Implements hook_requirements().
15 function demo_umami_requirements($phase) {
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,
31 * Implements hook_install().
33 * Perform actions to set up the site for this profile.
35 * @see system_install()
37 function demo_umami_install() {
38 // Set front page to "node".
39 \Drupal::configFactory()->getEditable('system.site')->set('page.front', '/node')->save(TRUE);
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);
45 // Assign user 1 the "administrator" role.
46 $user = User::load(1);
47 $user->roles[] = 'administrator';
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();
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]);
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']);
62 // Allow authenticated users to use shortcuts.
63 user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access shortcuts']);
65 // Populate the default shortcut set.
66 $shortcut = Shortcut::create([
67 'shortcut_set' => 'default',
68 'title' => t('Add content'),
70 'link' => ['uri' => 'internal:/node/add'],
74 $shortcut = Shortcut::create([
75 'shortcut_set' => 'default',
76 'title' => t('All content'),
78 'link' => ['uri' => 'internal:/admin/content'],
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']);
86 // Enable the admin theme.
87 \Drupal::configFactory()->getEditable('node.settings')->set('use_admin_theme', TRUE)->save(TRUE);
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);