lightning_core-8.x-5.3/modules/lightning_search/lightning_search.install
modules/lightning_search/lightning_search.install
<?php
/**
* @file
* Contains installation and update routines for Lightning Search.
*/
use Drupal\node\Entity\NodeType;
use Drupal\search_api\Entity\Index;
use Drupal\search_api\Entity\Server;
/**
* Implements hook_install().
*/
function lightning_search_install() {
// Don't make any configuration changes during config sync.
if (\Drupal::isConfigSyncing()) {
return;
}
// Search API DB is not a hard dependency, but install it so that the search
// index we provide will "just work" out of the box.
Drupal::service('module_installer')->install(['search_api_db']);
$server = Server::load('database');
if ($server) {
Index::load('content')->setServer($server)->enable()->save();
}
/** @var \Drupal\node\NodeTypeInterface $node_type */
$node_types = NodeType::loadMultiple();
array_walk($node_types, 'lightning_search_node_type_insert');
}
/**
* Implements hook_update_dependencies().
*/
function lightning_search_update_dependencies() {
return [
'block_content' => [
8300 => [
// block_content 8300 updates entity type definitions, which implicitly
// touches a lot of Search API configuration because entity type
// definition updates trigger Views cache rebuilds, which in turn
// triggers a lot of work, especially plugin instantiation, in Search
// API. So, if the configuration isn't fully up-to-date, things are
// likely to go kaboom. This ensures that Search API configuration is
// up-to-date before block_content 8300 updates entity type definitions.
'search_api' => 8104,
],
],
];
}
