external_entities-8.x-2.x-dev/modules/xntt_example_d7import/xntt_example_d7import.install
modules/xntt_example_d7import/xntt_example_d7import.install
<?php
/**
* @file
* Install, update and uninstall functions for the external_entities module.
*/
/**
* Implements hook_requirements().
*/
function xntt_example_d7import_requirements($phase) {
$requirements = [];
if ($phase === 'install') {
$xntt_storage = \Drupal::entityTypeManager()->getStorage('external_entity_type');
$xntt_types = $xntt_storage
->getQuery()
->accessCheck(FALSE)
->condition('id', ['d7import'], 'IN')
->execute();
if (!empty($xntt_types)) {
$requirements['xntt_example_d7import_extypes'] = [
'title' => t('External entity type Drupal 7 import example'),
'description' => t("The 'Drupal 7 content' external entity content type already exists and should be removed to install this module."),
'severity' => REQUIREMENT_ERROR,
];
}
}
return $requirements;
}
/**
* Implements hook_uninstall().
*/
function xntt_example_d7import_uninstall() {
// Since we prevented the user from removing the type, we need to remove it
// here.
$d7import_type = \Drupal::entityTypeManager()
->getStorage('external_entity_type')
->load('d7import');
if (!empty($d7import_type)) {
$d7import_type->delete();
}
}
