standard.install 2.6 KB

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