function apachesolr_entity_info_alter in Apache Solr Search 8
Same name and namespace in other branches
- 7 apachesolr.module \apachesolr_entity_info_alter()
Implements hook_entity_info_alter().
File
- ./
apachesolr.module, line 1849 - Integration with the Apache Solr search application.
Code
function apachesolr_entity_info_alter(&$entity_info) {
// Load all environments
$environments = apachesolr_load_all_environments();
// Set those values that we know. Other modules can do so
// for their own entities if they want.
$default_entity_info = array();
$default_entity_info['node']['indexable'] = TRUE;
$default_entity_info['node']['status callback'][] = 'apachesolr_index_node_status_callback';
$default_entity_info['node']['document callback'][] = 'apachesolr_index_node_solr_document';
$default_entity_info['node']['reindex callback'] = 'apachesolr_index_node_solr_reindex';
$default_entity_info['node']['bundles changed callback'] = 'apachesolr_index_node_bundles_changed';
$default_entity_info['node']['index_table'] = 'apachesolr_index_entities_node';
$default_entity_info['node']['cron_check'] = 'apachesolr_index_node_check_table';
// apachesolr_search implements a new callback for every entity type
// $default_entity_info['node']['result callback'] = 'apachesolr_search_node_result';
//Allow implementations of HOOK_apachesolr_entity_info to modify these default indexers
drupal_alter('apachesolr_entity_info', $default_entity_info);
// First set defaults so that we don't need to worry about NULL keys.
foreach (array_keys($entity_info) as $type) {
if (!isset($entity_info[$type]['apachesolr'])) {
$entity_info[$type]['apachesolr'] = array();
}
if (isset($default_entity_info[$type])) {
$entity_info[$type]['apachesolr'] += $default_entity_info[$type];
}
$default = array(
'indexable' => FALSE,
'status callback' => '',
'document callback' => '',
'reindex callback' => '',
'bundles changed callback' => '',
);
$entity_info[$type]['apachesolr'] += $default;
}
// For any supported entity type and bundle, flag it for indexing.
foreach ($entity_info as $entity_type => $info) {
if ($info['apachesolr']['indexable']) {
// Loop over each environment and check if any of them have other entity
// bundles of any entity type enabled and set the index value to TRUE
foreach ($environments as $env) {
// Skip if the environment is set to read only
if (empty($env['env_id']['conf']['apachesolr_read_only'])) {
// Get the supported bundles
$supported = apachesolr_get_index_bundles($env['env_id'], $entity_type);
// For each bundle in drupal, compare to the supported apachesolr
// bundles and enable where possible
foreach (array_keys($info['bundles']) as $bundle) {
if (in_array($bundle, $supported)) {
$entity_info[$entity_type]['bundles'][$bundle]['apachesolr']['index'] = TRUE;
}
}
}
}
}
}
}