function lightning_search_install in Lightning Core 8
Same name and namespace in other branches
- 8.5 modules/lightning_search/lightning_search.install \lightning_search_install()
- 8.2 modules/lightning_search/lightning_search.install \lightning_search_install()
- 8.3 modules/lightning_search/lightning_search.install \lightning_search_install()
- 8.4 modules/lightning_search/lightning_search.install \lightning_search_install()
Implements hook_install().
File
- modules/
lightning_search/ lightning_search.install, line 16 - Contains installation and update routines for Lightning Search.
Code
function lightning_search_install() {
// Search API DB is not a hard dependency, but install it if it's available so
// that the search index we provide will "just work" out of the box.
$module_data = system_rebuild_module_data();
if (isset($module_data['search_api_db'])) {
\Drupal::service('module_installer')
->install([
'search_api_db',
]);
}
// Don't make any configuration changes during config sync.
if (\Drupal::isConfigSyncing()) {
return;
}
/** @var \Drupal\node\NodeTypeInterface $node_type */
$node_types = NodeType::loadMultiple();
array_walk($node_types, 'lightning_search_node_type_insert');
// The database server is optional configuration, to be installed only if
// Search API DB is present. For some reason, it's not installed during a
// normal site install, so create it now if it doesn't already exist.
$server = Server::load('database');
if (empty($server) && \Drupal::moduleHandler()
->moduleExists('search_api_db')) {
Config::forModule('lightning_search')
->optional()
->getEntity('search_api_server', 'database')
->save();
$server = Server::load('database');
}
if ($server) {
Index::load('content')
->setServer($server)
->enable()
->save();
}
}