api-8.x-1.x-dev/modules/api_search_api_solr_defaults/api_search_api_solr_defaults.install
modules/api_search_api_solr_defaults/api_search_api_solr_defaults.install
<?php
/**
* @file
* Install and uninstall functions for the API Solr Search-API Defaults module.
*/
/**
* Implements hook_requirements().
*/
function api_search_api_solr_defaults_requirements($phase) {
$requirements = [];
if ($phase == 'install') {
if (\Drupal::moduleHandler()->moduleExists('search_api_solr')) {
$entities_to_check = [
'search_api_index' => 'default_api_solr_index',
'search_api_server' => 'default_solr_server',
'view' => 'api_search_api_solr',
];
/** @var \Drupal\Core\Entity\EntityTypeManager $entity_type_manager */
$entity_type_manager = \Drupal::service('entity_type.manager');
foreach ($entities_to_check as $entity_type => $entity_id) {
// Find out if the entity is already in place. If so, fail to install
// the module.
$entity_storage = $entity_type_manager->getStorage($entity_type);
$entity_storage->resetCache();
$entity = $entity_storage->load($entity_id);
if ($entity) {
$requirements['api_search_api_solr_defaults:defaults_exist'] = [
'severity' => REQUIREMENT_ERROR,
'description' => t('It looks like the default setup provided by this module already exists on your site. Cannot re-install module.'),
];
break;
}
}
}
}
return $requirements;
}
/**
* Implements hook_install().
*/
function api_search_api_solr_defaults_install() {
// Clear the display plugin cache after installation so the plugin for the new
// view (display) gets found.
\Drupal::service('plugin.manager.search_api.display')
->clearCachedDefinitions();
}
