You are here

scheduler_api_test.install in Scheduler 8

Same filename and directory in other branches
  1. 2.x tests/modules/scheduler_api_test/scheduler_api_test.install

Install and uninstall hooks for the Scheduler API Test module.

File

tests/modules/scheduler_api_test/scheduler_api_test.install
View source
<?php

/**
 * @file
 * Install and uninstall hooks for the Scheduler API Test module.
 */

/**
 * Implements hook_uninstall().
 *
 * Although not strictly necessary for testing, it is good practice to tidy up
 * module config and content on uninstalling. Plus, when developing this module
 * and enabling it manually as a real module, this code is needed to clean up,
 * otherwise a re-install fails.
 */
function scheduler_api_test_uninstall() {

  // Delete any content that may have been created for the custom node type.
  $nids_query = \Drupal::database()
    ->select('node', 'n')
    ->fields('n', [
    'nid',
  ])
    ->condition('n.type', [
    'scheduler_api_test',
  ], 'IN')
    ->execute();
  if ($nids = $nids_query
    ->fetchCol()) {
    $storage = \Drupal::entityTypeManager()
      ->getStorage('node');
    $entities = $storage
      ->loadMultiple($nids);
    $storage
      ->delete($entities);
    \Drupal::messenger()
      ->addMessage(t('@number %type node(s) have been deleted.', [
      '@number' => count($nids),
      '%type' => 'scheduler_api_test',
    ]));
  }

  // The content type, custom fields and storage are deleted automatically by
  // having 'enforced: module: - scheduler_api_test' in the
  // config/install/*.yml files.
}

Functions