toolshed-8.x-1.x-dev/modules/toolshed_search/toolshed_search.module
modules/toolshed_search/toolshed_search.module
<?php
/**
* @file
* Drupal hooks and global functionality for toolshed_search module.
*/
/**
* Implements hook_module_implements_alter().
*/
function toolshed_search_module_implements_alter(&$implementations, $hook): void {
if ($hook === 'search_api_server_load') {
// Move the module's search_api_server_load() hook to the front of the
// registry. This allows other modules to work on the replaced
// search_api_solr connector changes.
$implementations = [
'toolshed_search' => $implementations['toolshed_search'],
] + $implementations;
}
}
/**
* Implements hook_search_api_server_load().
*/
function toolshed_search_search_api_server_load(array $entities): void {
/** @var Drupal\toolshed_search\Utility\SearchServerHelper */
$server_helper = \Drupal::service('toolshed_search.server_helper');
/** @var \Drupal\search_api\Entity\Server[] $entities */
foreach ($entities as $server) {
// Search for servers which have toolshed search connectors and alter
// the connector as needed based on the current Drupal settings values.
// These can override the connector settings to support environment
// specific handling (like Acquia or Pantheon connectors).
$server_helper->alterBackendConnector($server);
}
}
/**
* Implements hook_search_api_index_load().
*/
function toolshed_search_search_api_index_load(array $entities): void {
/** @var \Drupal\toolshed_search\Utility\SearchServerHelper */
$server_helper = \Drupal::service('toolshed_search.server_helper');
/** @var \Drupal\search_api\IndexInterface $index */
foreach ($entities as &$index) {
// If index is already set as read-only, no need to check server settings.
if (!$index->get('read_only')) {
// Apply the read-only flag to all indexes where the server is read-only.
$server_helper->applyServerReadOnly($index);
}
}
}
/**
* {@inheritdoc}
*/
function toolshed_search_theme(array $exists, $type, $theme, $path): array {
return [
'toolshed_search_filter_form' => [
'render element' => 'form',
'pattern' => 'toolshed_search_filter_form__',
'file' => 'toolshed_search.theme',
],
];
}
