demo_umami.install 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\shortcut\Entity\Shortcut;
  8. /**
  9. * Implements hook_requirements().
  10. */
  11. function demo_umami_requirements($phase) {
  12. $requirements = [];
  13. if ($phase == 'runtime') {
  14. $profile = \Drupal::installProfile();
  15. $info = system_get_info('module', $profile);
  16. $requirements['experimental_profile_used'] = [
  17. 'title' => t('Experimental installation profile used'),
  18. 'value' => $info['name'],
  19. '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.'),
  20. 'severity' => REQUIREMENT_WARNING,
  21. ];
  22. }
  23. return $requirements;
  24. }
  25. /**
  26. * Implements hook_install().
  27. *
  28. * Perform actions to set up the site for this profile.
  29. *
  30. * @see system_install()
  31. */
  32. function demo_umami_install() {
  33. // Assign user 1 the "administrator" role.
  34. $user = User::load(1);
  35. $user->roles[] = 'administrator';
  36. $user->save();
  37. // We install some menu links, so we have to rebuild the router, to ensure the
  38. // menu links are valid.
  39. \Drupal::service('router.builder')->rebuildIfNeeded();
  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. // Enable the demo content module. This can't be specified as a dependency
  56. // in the demo_umami.info.yml file, as it requires configuration provided by
  57. // the profile (fields etc.).
  58. \Drupal::service('module_installer')->install(['demo_umami_content'], TRUE);
  59. }