View source
<?php
require_once 'sarnia.field_formatter.inc';
require_once 'sarnia.openlayers.inc';
function sarnia_menu() {
$items = array();
$items['admin/config/search/search_api/server/%search_api_server/sarnia'] = array(
'title' => 'Sarnia',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'sarnia_entity_manage_form',
5,
),
'access callback' => '_sarnia_entity_manage_form_access',
'access arguments' => array(
5,
),
'file' => 'sarnia.entities.inc',
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_INLINE | MENU_CONTEXT_PAGE,
);
$items['admin/config/search/search_api/server/%search_api_server/sarnia/manage'] = array(
'title' => 'Manage entity',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/config/search/search_api/server/%search_api_server/sarnia/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'sarnia_entity_delete_form',
5,
),
'access callback' => '_sarnia_entity_manage_form_access',
'access arguments' => array(
5,
),
'file' => 'sarnia.entities.inc',
'type' => MENU_CALLBACK,
);
$items['admin/config/search/search_api/server/%search_api_server/sarnia/cache'] = array(
'title' => 'Refresh server field cache',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'sarnia_entity_cache_form',
5,
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'sarnia.entities.inc',
'type' => MENU_CALLBACK,
);
$items['admin/config/search/search_api/server/%search_api_server/sarnia/properties'] = array(
'title' => 'Solr properties',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'sarnia_entity_properties_form',
5,
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'sarnia.entities.inc',
'type' => MENU_LOCAL_TASK,
);
$items['admin/config/search/search_api/server/%search_api_server/sarnia/schema'] = array(
'title' => 'Solr Schema',
'page callback' => 'sarnia_schema_page',
'page arguments' => array(
5,
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'sarnia.rules.inc',
'type' => MENU_LOCAL_TASK,
);
$items['sarnia/%sarnia_entity_type/%sarnia'] = array(
'title' => 'A Sarnia Entity',
'load arguments' => array(
1,
2,
),
'page callback' => 'sarnia_entity_page',
'page arguments' => array(
1,
2,
),
'access arguments' => array(
'access sarnia entity pages',
),
);
return $items;
}
function sarnia_menu_alter(&$items) {
if (!module_exists('field_ui')) {
return;
}
foreach ($items as $path => $item) {
if (preg_match('#^admin/config/search/search_api/server/[^/]+/sarnia/(field|display)#', $path)) {
unset($items[$path]);
}
}
$base = array(
'page callback' => 'drupal_get_form',
'access callback' => 'user_access',
'access arguments' => array(
'administer site configuration',
),
'file' => 'field_ui.admin.inc',
'file path' => drupal_get_path('module', 'field_ui'),
);
$items['admin/config/search/search_api/server/%sarnia_entity_server_name/sarnia/fields'] = array(
'title' => 'Manage fields',
'page arguments' => array(
'field_ui_field_overview_form',
5,
5,
),
'type' => MENU_LOCAL_TASK,
'weight' => 9,
) + $base;
$items['admin/config/search/search_api/server/%sarnia_entity_server_name/sarnia/fields/%sarnia_field_ui_menu'] = array(
'load arguments' => array(
5,
'%map',
),
'title callback' => 'field_ui_menu_title',
'title arguments' => array(
8,
),
'access callback' => 'sarnia_field_ui_menu_access_callback',
'access arguments' => array(
'administer site configuration',
9,
),
'page callback' => 'sarnia_field_ui_menu_page_callback',
'page arguments' => array(
8,
),
) + $base;
$items['admin/config/search/search_api/server/%sarnia_entity_server_name/sarnia/display'] = array(
'title' => 'Manage display',
'page arguments' => array(
'field_ui_display_overview_form',
5,
5,
'default',
),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
) + $base;
$items['admin/config/search/search_api/server/%sarnia_entity_server_name/sarnia/display/default'] = array(
'title' => 'Default',
'page arguments' => array(
'field_ui_display_overview_form',
5,
5,
8,
),
'access callback' => '_field_ui_view_mode_menu_access',
'access arguments' => array(
5,
5,
8,
'user_access',
'administer site configuration',
),
'type' => MENU_DEFAULT_LOCAL_TASK,
) + $base;
foreach (sarnia_entity_types() as $type) {
$entity_info = entity_get_info($type['machine_name']);
$search_api_server = $type['search_api_server'];
if (is_array($entity_info['view modes'])) {
foreach ($entity_info['view modes'] as $view_mode => $view_mode_info) {
$items["admin/config/search/search_api/server/{$search_api_server}/sarnia/display/{$view_mode}"] = array(
'title' => $view_mode_info['label'],
'page arguments' => array(
'field_ui_display_overview_form',
$type['machine_name'],
$type['machine_name'],
$view_mode,
),
'access callback' => '_field_ui_view_mode_menu_access',
'access arguments' => array(
$type['machine_name'],
$type['machine_name'],
$view_mode,
'user_access',
'administer site configuration',
),
'type' => MENU_LOCAL_TASK,
) + $base;
}
}
}
}
function sarnia_permission() {
return array(
'administer sarnia entity types' => array(
'title' => t('Administer Sarnia entity types'),
),
'access sarnia entity pages' => array(
'title' => t('Access sarnia entity pages'),
),
);
}
function _sarnia_entity_manage_form_access($server) {
return $server->class == 'sarnia_solr_service' && user_access('administer sarnia entity types');
}
function sarnia_entity_types($reset = FALSE) {
$entity_types =& drupal_static(__FUNCTION__);
if (!isset($entity_types) || $reset) {
$entity_types = array();
foreach (entity_get_info() as $type_name => $type) {
if ($type['controller class'] == 'SarniaController') {
$entity_types[$type_name] = $type['bundles'][$type_name];
}
}
}
return $entity_types;
}
function sarnia_entity_type_load($machine_name) {
$entity_types = sarnia_entity_types();
if (isset($entity_types[$machine_name])) {
return $entity_types[$machine_name];
}
return FALSE;
}
function sarnia_entity_type_load_by_index($index_machine_name) {
foreach (sarnia_entity_types() as $entity_type) {
if ($entity_type['search_api_index'] == $index_machine_name) {
return $entity_type;
}
}
return FALSE;
}
function sarnia_entity_server_name_load($server_name) {
foreach (sarnia_entity_types() as $entity_type) {
if ($entity_type['search_api_server'] == $server_name) {
return $entity_type['machine_name'];
}
}
return FALSE;
}
function sarnia_field_ui_menu_load($field_name, $server_name, $map = array()) {
$entity_type = sarnia_entity_server_name_load($server_name);
return field_ui_menu_load($field_name, $entity_type, $entity_type, 0, array());
}
function sarnia_field_ui_menu_access_callback($perm, $path) {
return user_access($perm) && (!$path || in_array($path, array(
'edit',
'field-settings',
'widget-type',
'delete',
)));
}
function sarnia_field_ui_menu_page_callback($field, $path = 'edit') {
switch ($path) {
case 'field-settings':
$form = 'field_ui_field_settings_form';
break;
case 'widget-type':
$form = 'field_ui_widget_type_form';
break;
case 'delete':
$form = 'field_ui_field_delete_form';
break;
case 'edit':
default:
$form = 'field_ui_field_edit_form';
}
return drupal_get_form($form, $field);
}
function sarnia_load($entity_id, $entity_type) {
if ($entities = entity_load($entity_type, array(
$entity_id,
))) {
return $entities[$entity_id];
}
return FALSE;
}
function sarnia_entity_page($entity_type, $entity) {
return sarnia_view($entity);
}
function sarnia_help($path, $arg) {
if ($path == 'admin/config/search/search_api/server/%/sarnia') {
return t("Sarnia can provide an entity type based on data that already exists in this Solr core. This is most useful for Solr cores that contain non-Drupal data that is indexed by an external process, since it allows you to use data stored in Solr within Drupal. In combination with a read-only Search API index, you can also build Views based on the Solr data.");
}
if ($path == 'admin/help#sarnia') {
$filepath = dirname(__FILE__) . '/README.md';
if (file_exists($filepath)) {
$readme = file_get_contents($filepath);
}
else {
$filepath = dirname(__FILE__) . '/README.txt';
if (file_exists($filepath)) {
$readme = file_get_contents($filepath);
}
}
if (!isset($readme)) {
return NULL;
}
if (module_exists('markdown')) {
$filters = module_invoke('markdown', 'filter_info');
$info = $filters['filter_markdown'];
if (function_exists($info['process callback'])) {
$output = $info['process callback']($readme, NULL);
}
else {
$output = '<pre>' . $readme . '</pre>';
}
}
else {
$output = '<pre>' . $readme . '</pre>';
}
return $output;
}
}
function sarnia_theme($existing, $type, $theme, $path) {
return array(
'sarnia_entity' => array(
'render element' => 'elements',
'template' => 'sarnia-entity',
),
'sarnia_schema_rule_form' => array(
'file' => 'sarnia.rules.inc',
'render element' => 'form',
),
);
}
function sarnia_entity_info() {
$entities = array();
module_load_include('inc', 'sarnia', 'sarnia.entities');
foreach (_sarnia_entity_types() as $machine_name => $type) {
$entities[$machine_name] = array(
'label' => $type['label'],
'controller class' => 'SarniaController',
'fieldable' => TRUE,
'static cache' => TRUE,
'uri callback' => 'sarnia_uri',
'view callback' => 'sarnia_view_multiple',
'base table' => NULL,
'entity keys' => array(
'id' => 'id',
'revision' => FALSE,
'bundle' => FALSE,
),
'bundles' => array(
$machine_name => array_merge($type, array(
'admin' => array(
'path' => "admin/config/search/search_api/server/{$type['search_api_server']}/sarnia",
),
)),
),
'view modes' => array(),
);
}
return $entities;
}
function sarnia_uri($entity) {
return array(
'path' => "sarnia/{$entity->type}/{$entity->id}",
);
}
function sarnia_entity_property_info() {
module_load_include('inc', 'sarnia', 'sarnia.entities');
$info = array();
$entity_types = _sarnia_entity_types();
foreach ($entity_types as $machine_name => $entity_info) {
$info[$machine_name]['properties'] = array();
$server = search_api_server_load($entity_info['search_api_server']);
if ($server) {
foreach ($server
->getFulltextFields() as $key => $field) {
$info[$machine_name]['properties'][$key] = array(
'label' => $key,
'type' => 'text',
);
}
foreach ($server
->getRemoteFields() as $key => $field) {
if ($field
->getType() == 'tdate') {
$info[$machine_name]['properties'][$key] = array(
'label' => $key,
'type' => 'date',
);
}
}
ksort($info[$machine_name]['properties']);
unset($info[$machine_name]['properties']['id']);
$info[$machine_name]['properties'] = array(
'id' => array(
'label' => t('Id'),
'type' => 'token',
'description' => t('An id from Solr.'),
'required' => TRUE,
),
) + $info[$machine_name]['properties'];
}
}
return $info;
}
class SarniaController extends DrupalDefaultEntityController {
public function load($ids = array(), $conditions = array()) {
$entities = $this
->cacheGet($ids, $conditions);
if ($ids === FALSE || ($load_ids = array_diff($ids, array_keys($entities)))) {
$index = search_api_index_load($this->entityInfo['bundles'][$this->entityType]['search_api_index']);
$index
->server()
->disableFeature('search_api_facets');
$query = $index
->query(array(
'parse mode' => 'direct',
'sarnia use raw keys' => TRUE,
));
$id_field = $this->entityInfo['bundles'][$this->entityType]['id_field'];
do {
if (is_array($load_ids)) {
$keys = array();
$count = 0;
foreach ($load_ids as $i => $id) {
$keys[] = "{$id_field}:{$id}";
unset($load_ids[$i]);
$count++;
if ($count >= 200) {
break;
}
}
$query
->keys(implode(' OR ', $keys));
}
$query
->execute();
} while (is_array($load_ids) && !empty($load_ids));
$entities = $this
->cacheGet($ids, $conditions);
$index
->server()
->unDisableFeature('search_api_facets');
}
return $entities;
}
public function stash($results) {
$solr_document_field = '_data';
foreach (current(field_info_instances($this->entityType)) as $field_name => $instance) {
$field_info = field_info_field($field_name);
if ($field_info['type'] == 'sarnia') {
$solr_document_field = $field_name;
break;
}
}
$loaded_entities = array();
foreach ($results as $entity_id => $result) {
$loaded_entities[$entity_id] = (object) array(
'type' => $this->entityType,
$this->idKey => $entity_id,
$solr_document_field => $result['fields'],
);
}
if (!empty($loaded_entities)) {
$this
->attachLoad($loaded_entities);
}
$this
->cacheSet($loaded_entities);
}
}
function sarnia_field_info() {
return array(
'sarnia' => array(
'label' => t('Solr Document'),
'description' => t('Properties loaded from a Solr document.'),
'settings' => array(),
'instance_settings' => array(),
'default_widget' => 'sarnia_no_input',
'default_formatter' => 'sarnia_default',
'no_ui' => TRUE,
),
);
}
function sarnia_field_extra_fields() {
$extra = array();
foreach (sarnia_entity_types() as $name => $info) {
$extra[$name][$name]['display'] = array(
'sarnia_id' => array(
'label' => t('Sarnia: Id'),
'description' => t('The Sarnia entity id.'),
'weight' => 99,
),
'sarnia_solr_properties' => array(
'label' => t('Sarnia: Solr properties'),
'description' => t('The full set of Solr properties associated with this entity. Useful for debugging purposes.'),
'weight' => 100,
),
);
}
return $extra;
}
function sarnia_field_load($entity_type, $entities, $field, $instances, $langcode, &$items) {
foreach ($entities as $id => $entity) {
if (empty($entity->{$field['field_name']}) && isset($entity->_data)) {
$entity->{$field['field_name']} = (array) $entity->_data;
unset($entity->_data);
}
}
}
function sarnia_field_widget_info() {
return array(
'sarnia_no_input' => array(
'label' => 'No widget',
'description' => 'Do not provide an input form for this field.',
'field types' => array(
'sarnia',
),
'settings' => array(),
),
);
}
function sarnia_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
return array();
}
function sarnia_field_get_property($entity, $field, $property_name) {
$value = array();
$field_name = $field['field_name'];
if (isset($entity->{$field_name}) && isset($entity->{$field_name}[$property_name])) {
$value = $entity->{$field_name}[$property_name];
$value = is_array($value) ? $value : array(
$value,
);
}
return $value;
}
function sarnia_index_get_options($index_machine_name, $filter_method = NULL) {
$options = array();
if ($index = search_api_index_load($index_machine_name)) {
foreach ($index
->server()
->{$filter_method}() as $name => $field) {
$options[$field
->getName()] = $name;
}
asort($options);
}
return $options;
}
function sarnia_index_get_field_options($index_machine_name, $reset = FALSE) {
$options =& drupal_static(__FUNCTION__, array());
if (!isset($options[$index_machine_name]) || $reset) {
$options[$index_machine_name] = sarnia_index_get_options($index_machine_name, 'getDisplayFields');
}
return $options[$index_machine_name];
}
function sarnia_index_get_filter_options($index_machine_name, $reset = FALSE) {
$options =& drupal_static(__FUNCTION__, array());
if (!isset($options[$index_machine_name]) || $reset) {
$options[$index_machine_name] = sarnia_index_get_options($index_machine_name, 'getFilterFields');
}
return $options[$index_machine_name];
}
function sarnia_form_search_api_admin_index_edit_alter(&$form, &$form_state) {
if (($index = menu_get_object('search_api_index', 5)) && ($sarnia_type = sarnia_entity_type_load_by_index($index->machine_name))) {
$form['server']['#disabled'] = TRUE;
$form['server']['#description'] = t('This index uses the search server as a data source. You can not change the server on this type of index after it has been created.');
}
}
function sarnia_entity_load($entities, $type) {
if ($type == 'search_api_index') {
foreach ($entities as $entity) {
if ($entity
->server() && ($sarnia_type = sarnia_entity_type_load_by_index($entity->machine_name))) {
$prev_fields = array();
if (isset($entity->options['fields'])) {
$prev_fields = $entity->options['fields'];
}
$entity->options['fields'] = array();
foreach ($entity
->server()
->getRemoteFields() as $key => $field) {
$boost = '1.0';
if (!empty($prev_fields[$key]) && !empty($prev_fields[$key]['boost'])) {
$boost = $prev_fields[$key]['boost'];
}
$entity->options['fields'][$key] = array(
'name' => $key,
'indexed' => $field
->isIndexed(),
'type' => 'none',
'boost' => $boost,
);
}
foreach ($entity
->server()
->getFulltextFields() as $key => $field) {
$entity->options['fields'][$key]['type'] = 'text';
}
foreach ($entity
->server()
->getRemoteFields() as $key => $field) {
if ($field
->getType() == 'tdate') {
$entity->options['fields'][$key]['type'] = 'date';
}
}
ksort($entity->options['fields']);
}
}
}
}
function sarnia_views_api() {
return array(
'api' => '3.0-alpha1',
);
}
function sarnia_ctools_plugin_api($module, $api) {
if ($module == 'openlayers' && ($api == 'openlayers_maps' || $api == 'openlayers_layers')) {
return array(
'version' => 1,
);
}
}
function sarnia_search_api_server_delete(SearchApiServer $server) {
if ($server->class == 'sarnia_solr_server') {
$entity_type_machine_name = sarnia_entity_server_name_load($server->machine_name);
module_load_include('inc', 'sarnia', 'sarnia.entities');
sarnia_entity_type_delete($entity_type_machine_name);
entity_info_cache_clear();
menu_rebuild();
drupal_set_message(t('Deleted the Sarnia entity type and a Search API index for the %server_name server.', array(
'%server_name' => $server->name,
)));
}
}
function sarnia_search_api_service_info() {
$services['sarnia_solr_service'] = array(
'name' => t('Sarnia Solr service'),
'description' => t('Search-only connection to a Solr core.'),
'class' => 'SarniaSolrService',
);
return $services;
}
function sarnia_element_add_combobox(&$element) {
$element['#attributes']['class'][] = 'combobox';
}
function sarnia_view(&$entity, $view_mode = 'default', $langcode = NULL) {
if (!isset($langcode)) {
$langcode = $GLOBALS['language_content']->language;
}
sarnia_build_content($entity, $view_mode, $langcode);
$build = $entity->content;
unset($entity->content);
$build += array(
'#theme' => 'sarnia_entity',
'#entity' => $entity,
'#view_mode' => $view_mode,
'#language' => $langcode,
);
drupal_alter('entity_view', $build, $entity->type);
return $build;
}
function sarnia_view_multiple($entities, $view_mode = 'default', $langcode = NULL) {
$output = array();
foreach ($entities as $entity) {
$output[$entity->id] = sarnia_view($entity, $view_mode, $langcode);
}
return $output;
}
function sarnia_build_content($entity, $view_mode, $langcode = NULL) {
if (!isset($langcode)) {
$langcode = $GLOBALS['language_content']->language;
}
$entity->content = array();
$entity->content['sarnia_id'] = array();
$entity->content['sarnia_id']['title'] = array(
'#type' => 'html_tag',
'#tag' => 'h4',
'#value' => t('Id'),
);
$entity->content['sarnia_id']['value'] = array(
'#type' => 'html_tag',
'#tag' => 'pre',
'#value' => check_plain($entity->id),
);
$solr_document_field = '_data';
foreach (current(field_info_instances($entity->type)) as $field_name => $instance) {
$field_info = field_info_field($field_name);
if ($field_info['type'] == 'sarnia') {
$solr_document_field = $field_name;
break;
}
}
$entity->content['sarnia_solr_properties'] = array();
$entity->content['sarnia_solr_properties']['title'] = array(
'#type' => 'html_tag',
'#tag' => 'h4',
'#value' => t('Solr properties'),
);
$entity->content['sarnia_solr_properties']['value'] = array(
'#type' => 'html_tag',
'#tag' => 'pre',
'#value' => check_plain(print_r($entity->{$solr_document_field}, TRUE)),
);
field_attach_prepare_view($entity->type, array(
$entity->id => $entity,
), $view_mode, $langcode);
entity_prepare_view($entity->type, array(
$entity->id => $entity,
), $view_mode, $langcode);
$entity->content += field_attach_view($entity->type, $entity, $view_mode, $langcode);
module_invoke_all('entity_view', $entity, $entity->type, $view_mode, $langcode);
}
function template_preprocess_sarnia_entity(&$variables) {
$entity = $variables['elements']['#entity'];
foreach (element_children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
field_attach_preprocess($entity->type, $entity, $variables['elements'], $variables);
}
function sarnia_sarnia_solr_service_schema($conditions = array()) {
$conditions += array(
'enabled' => TRUE,
);
$query = db_select('sarnia_solr_service_schema', 'ss')
->fields('ss')
->orderBy('ss.behavior', 'ASC');
foreach ($conditions as $field => $value) {
$query
->condition('ss.' . $field, $value);
}
$query
->orderBy('ss.search_api_server', 'DESC');
$rule_order = $query
->addExpression("ss.match_type = 'name'", 'sort_1');
$query
->orderBy($rule_order, 'DESC');
$rule_order = $query
->addExpression("ss.match_type = 'dynamicBase'", 'sort_2');
$query
->orderBy($rule_order, 'DESC');
$rule_order = $query
->addExpression("ss.match_type = 'type'", 'sort_3');
$query
->orderBy($rule_order, 'DESC');
return $query
->execute()
->fetchAll();
}
function sarnia_sarnia_solr_service_schema_rule_load($id) {
return db_select('sarnia_solr_service_schema', 'ss')
->condition('id', $id)
->fields('ss')
->execute()
->fetch();
}
function sarnia_form_search_api_admin_confirm_alter(&$form, &$form_state) {
if ($form['type']['#value'] == 'index' && $form['action']['#value'] == 'delete') {
$index = $form_state['build_info']['args'][2];
if (($entity_type = sarnia_entity_type_load($index->machine_name)) && $entity_type['search_api_server'] == $index->server) {
$form['info'] = array(
'#type' => 'container',
'info' => array(
'#markup' => t("This index is created and managed by Sarnia. It will be deleted only when the Sarnia entity type is deleted. You can manage the Sarnia entity type by visiting the !link.", array(
'!link' => l(t('the server configuration section'), "admin/config/search/search_api/server/{$index->server}/sarnia"),
)),
),
);
$form['message']['#access'] = FALSE;
$form['description']['#access'] = FALSE;
$form['confirm']['#access'] = FALSE;
$form['actions']['#access'] = FALSE;
}
}
elseif ($form['type']['#value'] == 'server' && $form['action']['#value'] == 'delete') {
$server = $form_state['build_info']['args'][2];
if ($server->class == 'sarnia_solr_service') {
$sarnia_type = sarnia_entity_server_name_load($server->machine_name);
if ($sarnia_type) {
$form['info'] = array(
'#type' => 'container',
'info' => array(
'#markup' => t("This Search API Server has a Sarnia entity type enabled. Please delete the Sarnia entity type before deleting the server. You can manage the Sarnia entity type by visiting the !link.", array(
'!link' => l(t('the Sarnia configuration tab'), "admin/config/search/search_api/server/{$server->machine_name}/sarnia"),
)),
),
);
$form['message']['#access'] = FALSE;
$form['description']['#access'] = FALSE;
$form['confirm']['#access'] = FALSE;
$form['actions']['#access'] = FALSE;
}
}
}
}
function sarnia_facetapi_query_types() {
return array(
'sarnia_term' => array(
'handler' => array(
'class' => 'SarniaFacetapiTerm',
'adapter' => 'search_api',
),
),
);
}
function sarnia_facetapi_facet_info_alter(&$facet_info, $searcher_info) {
if ('search_api' == $searcher_info['adapter'] && ($sarnia_type = sarnia_entity_type_load_by_index($searcher_info['instance']))) {
$index = search_api_index_load($searcher_info['instance']);
$server = search_api_server_load($index->server);
if ($server) {
foreach ($server
->getDisplayFields() as $facet_name => $field) {
if (in_array($field
->getType(), array(
'tdate',
))) {
continue;
}
$facet_info[$facet_name] = array(
'name' => $facet_name,
'label' => $facet_name,
'description' => '',
'field' => $facet_name,
'field alias' => $facet_name,
'field api name' => FALSE,
'field api bundles' => array(),
'query types' => array(
'sarnia_term',
'term',
),
'alter callbacks' => array(),
'dependency plugins' => array(
'bundle',
'role',
),
'default widget' => FALSE,
'allowed operators' => array(
FACETAPI_OPERATOR_AND => TRUE,
FACETAPI_OPERATOR_OR => TRUE,
),
'facet missing allowed' => TRUE,
'facet mincount allowed' => TRUE,
'weight' => 0,
'map callback' => FALSE,
'map options' => array(),
'hierarchy callback' => FALSE,
'values callback' => FALSE,
'min callback' => FALSE,
'max callback' => FALSE,
'default sorts' => array(
array(
'active',
SORT_DESC,
),
array(
'count',
SORT_DESC,
),
array(
'display',
SORT_ASC,
),
),
);
if (module_exists('facetapi_bonus')) {
$facet_info[$facet_name]['dependency plugins'] = array(
'bundle',
'role',
'facet',
);
}
foreach ($server
->getFulltextFields() as $key => $field) {
unset($facet_info[$key]);
}
}
}
}
}
function sarnia_search_api_facetapi_keys_alter(&$keys, $query) {
if ($query instanceof SearchApiQuery && ($index = $query
->getIndex()) && sarnia_entity_type_load_by_index($index->machine_name)) {
$keys = drupal_get_title();
}
}
function sarnia_features_pipe_alter(&$pipe, $data, &$export) {
if (in_array($export['component'], array(
'search_api_index',
'sarnia_entity_type',
))) {
module_load_include('inc', 'sarnia', 'sarnia.entities');
$types = _sarnia_entity_types();
$depends = $export['component'] == 'sarnia_entity_type' ? 'search_api_index' : 'sarnia_entity_type';
foreach ($data as $component) {
if (in_array($component, array_keys($types))) {
$export['features'][$depends][$component] = $component;
}
}
}
}
function sarnia_ctools_plugin_post_alter(&$plugin, &$info) {
if ($plugin['module'] == 'facetapi' && ($plugin['name'] == 'facetapi_checkbox_links' || $plugin['name'] == 'facetapi_links')) {
$plugin['handler']['query types'][] = 'sarnia_term';
}
if ($plugin['module'] == 'facetapi_multiselect' && $plugin['name'] == 'facetapi_multiselect') {
$plugin['handler']['query types'][] = 'sarnia_term';
}
if ($plugin['module'] == 'facetapi_select' && $plugin['name'] == 'facetapi_select_dropdowns') {
$plugin['handler']['query types'][] = 'sarnia_term';
}
}