function search_api_system_info_alter in Search API 7
Implements hook_system_info_alter().
Checks if the module provides any search item types or service classes. If it does, and there are search indexes using those item types, respectively servers using those service classes, the module is set to "required".
Heavily borrowed from field_system_info_alter().
See also
hook_search_api_item_type_info()
File
- ./
search_api.module, line 802 - Provides a flexible framework for implementing search services.
Code
function search_api_system_info_alter(&$info, $file, $type) {
if ($type != 'module' || $file->name == 'search_api' || !module_exists($file->name)) {
return;
}
// Check for defined item types.
if (module_hook($file->name, 'search_api_item_type_info')) {
$types = array();
foreach (search_api_get_item_type_info() as $type => $type_info) {
if ($type_info['module'] == $file->name) {
$types[] = $type;
}
}
if ($types) {
$sql = 'SELECT machine_name, name FROM {search_api_index} WHERE item_type IN (:types)';
$indexes = db_query($sql, array(
':types' => $types,
))
->fetchAllKeyed();
if ($indexes) {
$info['required'] = TRUE;
$links = array();
foreach ($indexes as $id => $name) {
$url = url("admin/config/search/search_api/index/{$id}");
$links[] = '<a href="' . check_plain($url) . '">' . check_plain($name) . '</a>';
}
$args = array(
'!indexes' => implode(', ', $links),
);
$info['explanation'] = format_plural(count($indexes), 'Item type in use by the following index: !indexes.', 'Item type(s) in use by the following indexes: !indexes.', $args);
}
}
}
// Check for defined service classes.
if (module_hook($file->name, 'search_api_service_info')) {
$classes = array();
foreach (search_api_get_service_info() as $class => $class_info) {
if ($class_info['module'] == $file->name) {
$classes[] = $class;
}
}
if ($classes) {
$sql = 'SELECT machine_name, name FROM {search_api_server} WHERE class IN (:classes)';
$servers = db_query($sql, array(
':classes' => $classes,
))
->fetchAllKeyed();
if ($servers) {
$info['required'] = TRUE;
$links = array();
foreach ($servers as $id => $name) {
$url = url("admin/config/search/search_api/server/{$id}");
$links[] = '<a href="' . check_plain($url) . '">' . check_plain($name) . '</a>';
}
$args = array(
'!servers' => implode(', ', $links),
);
$explanation = format_plural(count($servers), 'Service class in use by the following server: !servers.', 'Service class(es) in use by the following servers: !servers.', $args);
$info['explanation'] = (!empty($info['explanation']) ? $info['explanation'] . ' ' : '') . $explanation;
}
}
}
}