forked from a64f7bb4-7358-4778-9fbe-3b882c34cc1d/v1
50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Install/update/uninstall functions for the Search API Autocomplete module.
|
|
*/
|
|
|
|
use Drupal\search_api\SearchApiException;
|
|
use Drupal\search_api_autocomplete\Entity\Search;
|
|
use Drupal\search_api_autocomplete\SearchApiAutocompleteException;
|
|
use Drupal\search_api_solr\SolrBackendInterface;
|
|
|
|
/**
|
|
* Implements hook_requirements().
|
|
*/
|
|
function search_api_autocomplete_requirements(string $phase): array {
|
|
if ($phase !== 'runtime'
|
|
|| !interface_exists(SolrBackendInterface::class)
|
|
|| version_compare(SolrBackendInterface::SEARCH_API_SOLR_SCHEMA_VERSION, '4.2.5', '<')
|
|
|| \Drupal::moduleHandler()->moduleExists('search_api_solr_autocomplete')) {
|
|
return [];
|
|
}
|
|
|
|
// Check that there really is at least one autocomplete search set up with a
|
|
// Solr server.
|
|
$searches = Search::loadMultiple();
|
|
foreach ($searches as $search) {
|
|
try {
|
|
$index = $search->getIndex();
|
|
if ($index->status()
|
|
&& $index->hasValidServer()
|
|
&& $index->getServerInstance()
|
|
->getBackend() instanceof SolrBackendInterface) {
|
|
return [
|
|
'search_api_solr_autocomplete' => [
|
|
'title' => 'Search API Solr Autocomplete',
|
|
'value' => t('When using a Solr server as the search backend, it is recommended to enable the "Search API Solr Autocomplete" module for improved autocomplete functionality.'),
|
|
'severity' => REQUIREMENT_WARNING,
|
|
],
|
|
];
|
|
}
|
|
}
|
|
catch (SearchApiException | SearchApiAutocompleteException $e) {
|
|
// Ignore.
|
|
}
|
|
}
|
|
|
|
return [];
|
|
}
|