demo_umami.profile 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * @file
  4. * Enables modules and site configuration for a demo_umami site installation.
  5. */
  6. use Drupal\contact\Entity\ContactForm;
  7. use Drupal\Core\Form\FormStateInterface;
  8. /**
  9. * Implements hook_form_FORM_ID_alter() for install_configure_form().
  10. *
  11. * Allows the profile to alter the site configuration form.
  12. */
  13. function demo_umami_form_install_configure_form_alter(&$form, FormStateInterface $form_state) {
  14. $form['site_information']['site_name']['#default_value'] = 'Umami Food Magazine';
  15. $form['#submit'][] = 'demo_umami_form_install_configure_submit';
  16. }
  17. /**
  18. * Submission handler to sync the contact.form.feedback recipient.
  19. */
  20. function demo_umami_form_install_configure_submit($form, FormStateInterface $form_state) {
  21. $site_mail = $form_state->getValue('site_mail');
  22. ContactForm::load('feedback')->setRecipients([$site_mail])->trustData()->save();
  23. $password = $form_state->getValue('account')['pass'];
  24. demo_umami_set_users_passwords($password);
  25. }
  26. /**
  27. * Sets the password of admin to be the password for all users.
  28. */
  29. function demo_umami_set_users_passwords($admin_password) {
  30. // Collect the IDs of all users with roles editor or author.
  31. $ids = \Drupal::entityQuery('user')
  32. ->condition('roles', ['author', 'editor'], 'IN')
  33. ->execute();
  34. $users = \Drupal::entityTypeManager()->getStorage('user')->loadMultiple($ids);
  35. foreach ($users as $user) {
  36. $user->setPassword($admin_password);
  37. $user->save();
  38. }
  39. }
  40. /**
  41. * Implements hook_toolbar().
  42. */
  43. function demo_umami_toolbar() {
  44. // Add a warning about using an experimental profile.
  45. // @todo This can be removed once a generic warning for experimental profiles
  46. // has been introduced. https://www.drupal.org/project/drupal/issues/2934374
  47. $items['experimental-profile-warning'] = [
  48. '#weight' => 999,
  49. '#cache' => [
  50. 'contexts' => ['route'],
  51. ],
  52. ];
  53. // Show warning only on administration pages.
  54. $admin_context = \Drupal::service('router.admin_context');
  55. if ($admin_context->isAdminRoute()) {
  56. $items['experimental-profile-warning']['#type'] = 'toolbar_item';
  57. $items['experimental-profile-warning']['tab'] = [
  58. '#type' => 'inline_template',
  59. '#template' => '<a class="toolbar-warning" href="{{ more_info_link }}">This site is intended for demonstration purposes.</a>',
  60. '#context' => [
  61. 'more_info_link' => 'https://www.drupal.org/node/2941833',
  62. ],
  63. '#attached' => [
  64. 'library' => ['demo_umami/toolbar-warning'],
  65. ],
  66. ];
  67. }
  68. return $items;
  69. }