-
Notifications
You must be signed in to change notification settings - Fork 1
/
elasticsearch_helper_views.module
80 lines (69 loc) · 2.27 KB
/
elasticsearch_helper_views.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_form_FORM_ID_alter().
*
* This code is borrowed from "views_block_filter_block" module.
*/
function elasticsearch_helper_views_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$storage = $form_state->getStorage();
$view = $storage['view'];
// Only react on block Views specifically configured with exposed form blocks.
if (get_class($view->display_handler) == 'Drupal\elasticsearch_helper_views\Plugin\views\display\ElasticsearchBlock') {
if ($view->display_handler->getOption('exposed_block')) {
// Ensure that the fallback form action is the current page.
$request = \Drupal::request();
$url = Url::createFromRequest($request);
$url->setAbsolute();
$form['#action'] = $url->toString();
}
}
}
/**
* Implements hook_views_data().
*
* Use hook_views_data_alter() hook to alter or add fields or filters to
* "elasticsearch_result" data type.
*
* @see hook_views_data_alter()
*/
function elasticsearch_helper_views_views_data() {
$data = [];
$data['elasticsearch_result']['table']['group'] = t('Elasticsearch result');
$data['elasticsearch_result']['table']['base'] = [
'field' => 'id',
'title' => t('Elasticsearch result'),
'help' => t('Elasticsearch result'),
'query_id' => 'elasticsearch_query',
];
$data['elasticsearch_result']['entity_relationship'] = [
'relationship' => [
'id' => 'entity_relationship',
'title' => t('Entity relationship'),
'base' => 'elasticsearch_result',
],
];
$data['elasticsearch_result']['rendered_entity'] = [
'field' => [
'title' => t('Rendered entity'),
'help' => t('Renders an entity in a view mode.'),
'id' => 'elasticsearch_rendered_entity',
],
];
$data['elasticsearch_result']['source'] = [
'title' => t('Source field'),
'help' => t('Returns a value from the "_source" field.'),
'field' => [
'id' => 'elasticsearch_source',
],
];
$data['elasticsearch_result']['bulk_form'] = [
'field' => [
'title' => t('Bulk form'),
'help' => t('Provides bulk form to perform operation on Elasticsearch documents.'),
'id' => 'elasticsearch_bulk_form',
],
];
return $data;
}