uw_base_profile.profile 2.34 KB
Newer Older
1
2
3
4
5
6
7
8
<?php

/**
 * @file
 * Enables modules and site configuration for a standard site installation.
 */

use Drupal\Core\Form\FormStateInterface;
9
use Drupal\Core\Site\Settings;
10
11
12
13
14
15
16

/**
 * Implements hook_form_FORM_ID_alter() for install_configure_form().
 *
 * Allows the profile to alter the site configuration form.
 */
function uw_base_profile_form_install_configure_form_alter(&$form, FormStateInterface $form_state) {
Liam Morland's avatar
Liam Morland committed
17
  // Account information defaults.
18
  $form['admin_account']['account']['name']['#default_value'] = 'wcmsadmin';
19
20
  $form['site_information']['site_mail']['#default_value'] = 'wcmsadmi@uwaterloo.ca';
  $form['admin_account']['account']['mail']['#default_value'] = 'wcmsadmi@uwaterloo.ca';
21

Liam Morland's avatar
Liam Morland committed
22
  // Date/time settings.
23
24
25
  $form['regional_settings']['site_default_country']['#default_value'] = 'CA';
  $form['regional_settings']['date_default_timezone']['#default_value'] = 'America/Toronto';

Liam Morland's avatar
Liam Morland committed
26
  // Update notification defaults.
27
28
  $form['update_notifications']['enable_update_status_emails']['#default_value'] = 0;
}
29
30
31
32
33

/**
 * Implements hook_install_tasks().
 */
function uw_base_profile_install_tasks(&$install_state) {
Liam Morland's avatar
Liam Morland committed
34
  $tasks['uw_base_profile_conditional_installs'] = [
35
36
    'display_name' => 'University of Waterloo conditional installs',
    'type' => 'normal',
Liam Morland's avatar
Liam Morland committed
37
  ];
38
39
40
41
42
43
44
45
46
  return $tasks;
}

/**
 * Callback for uw_base_profile_conditional_installs task.
 */
function uw_base_profile_conditional_installs() {
  $is_dev = Settings::get('uw_dev_site', FALSE);
  if ($is_dev) {
Liam Morland's avatar
Liam Morland committed
47
    $modules = ['uw_site_dev'];
48
49
    \Drupal::service('module_installer')->install($modules, TRUE);
  }
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

  // Enforce wcmsadmi@uwaterloo.ca as the site email if the default was used.
  $config = \Drupal::service('config.factory')->getEditable('system.site');
  if ($config->get('mail') == 'admin@example.com') {
    $config->set('mail', 'wcmsadmi@uwaterloo.ca')->save();
  }
  // Enforce wcmsadmi@uwaterloo.ca as the wcmsadmin user email if the default was used.
  $user = user_load_by_name('wcmsadmin');
  if ($user && $user->getEmail() == 'admin@example.com') {
    $user->setEmail('wcmsadmi@uwaterloo.ca');
    $user->save();
  }
  // Enforce not sending update emails if the default was used.
  $config = \Drupal::service('config.factory')->getEditable('update.settings');
  if (in_array('admin@example.com', $config->get('notification.emails'))) {
    $config->set('notification.emails', [])->save();
  }
67
}