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