uw_sites_all.install 2.3 KB
Newer Older
Liam Morland's avatar
Liam Morland committed
1 2 3 4 5 6 7 8 9 10 11 12 13
<?php

/**
 * @file
 * Install, update and uninstall for UW Sites all.
 */

/**
 * Implements hook_install().
 */
function uw_sites_all_install() {
  // Add web resources news feed.
  $title = 'Web-resources news';
14 15
  $database = \Drupal::database();
  $fid = $database->query('SELECT fid FROM {aggregator_feed} WHERE title = :title', [':title' => $title])->fetchCol();
Liam Morland's avatar
Liam Morland committed
16 17 18 19 20 21 22 23 24 25

  if (empty($fid)) {
    $feed = \Drupal::entityTypeManager()->getStorage('aggregator_feed')->create([
      'uuid' => \Drupal::service('uuid')->generate(),
      'title' => $title,
      'url' => 'https://uwaterloo.ca/web-resources/news/news.xml',
      'created' => time(),
    ]);
    $feed->save();
  }
26

Liam Morland's avatar
Liam Morland committed
27
  // Make sure the theme is installed.
28 29 30
  $theme_handler = \Drupal::service('theme_handler');
  $theme_handler->install(['uw_theme_admin']);

Liam Morland's avatar
Liam Morland committed
31
  // Set it as the admin theme.
32 33
  $config = \Drupal::service('config.factory')->getEditable('system.theme');
  $config->set('admin', 'uw_theme_admin')->save();
34 35 36

  // Remove default "contact" form.
  \Drupal::entityTypeManager()->getStorage('webform')->load('contact')->delete();
Liam Morland's avatar
Liam Morland committed
37 38 39 40 41 42
}

/**
 * Implements hook_uninstall().
 */
function uw_sites_all_uninstall() {
Liam Morland's avatar
Liam Morland committed
43
  // phpcs:disable DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable
Liam Morland's avatar
Liam Morland committed
44 45 46
  $transaction = \Drupal::database()->startTransaction();

  $title = "Web-resources news";
47 48
  $database = \Drupal::database();
  $fid = $database->query('SELECT fid FROM {aggregator_feed} WHERE title = :title', [':title' => $title])->fetchCol();
Liam Morland's avatar
Liam Morland committed
49
  if (!empty($fid)) {
50 51 52 53 54 55 56 57

    $query = $database->delete('aggregator_feed');
    $query->condition('fid', $fid);
    $query->execute();

    $query = $database->delete('aggregator_item');
    $query->condition('fid', $fid);
    $query->execute();
Liam Morland's avatar
Liam Morland committed
58 59
  }
}
60

Liam Morland's avatar
Liam Morland committed
61 62 63 64
/**
 * Implements hook_update_N().
 */

65 66 67 68 69 70
/**
 * Enables OFIS module.
 */
function uw_sites_all_update_8101(&$sandbox) {
  \Drupal::service('module_installer')->install(['uw_ws_ofis']);
}
71 72 73 74 75 76 77

/**
 * Enables UW CKEditor Plugins module.
 */
function uw_sites_all_update_8102(&$sandbox) {
  \Drupal::service('module_installer')->install(['uw_ckeditor_plugins']);
}
78 79 80 81 82 83 84 85

/**
 * Protect all Webforms with Honeypot.
 */
function uw_sites_all_update_8103() {
  $config = \Drupal::service('config.factory')->getEditable('webform.settings');
  $config->set('third_party_settings.honeypot.honeypot', TRUE)->save();
}