demo_umami.install 3.2 KB

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