forked from openeuropa/oe_list_pages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oe_list_pages.module
111 lines (103 loc) · 3.38 KB
/
oe_list_pages.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* @file
* The OpenEuropa List Pages module.
*/
declare(strict_types = 1);
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_facets_search_api_query_type_mapping_alter().
*/
function oe_list_pages_facets_search_api_query_type_mapping_alter($backend_plugin_id, array &$query_types) {
// We need to define a new query type to be used by full text list facets,
// which will apply query logic required for text search.
$query_types['fulltext_comparison'] = 'fulltext_query_type';
$query_types['date_comparison'] = 'date_query_type';
$query_types['oe_list_pages_date_status_comparison'] = 'oe_list_pages_date_status_query_type';
}
/**
* Implements hook_theme().
*/
function oe_list_pages_theme($existing, $type, $theme, $path) {
return [
'oe_list_pages_selected_facet' => [
'variables' => [
'items' => [],
'label' => NULL,
],
],
'oe_list_pages_rss' => [
'variables' => [
'title' => '',
'link' => '',
'atom_link' => '',
'channel_description' => '',
'language' => '',
'copyright' => '',
'image' => [],
'channel_elements' => [],
'items' => [],
],
],
'oe_list_pages_rss_item' => [
'variables' => [
'title' => '',
'link' => '',
'guid' => '',
'item_description' => '',
'item_elements' => [],
],
],
];
}
/**
* Implements hook_locale_translation_projects_alter().
*/
function oe_list_pages_locale_translation_projects_alter(&$projects) {
$projects['oe_list_pages']['info']['interface translation server pattern'] = drupal_get_path('module', 'oe_list_pages') . '/translations/%project-%language.po';
}
/**
* Implements hook_form_BASE_FORM_ID_alter().
*/
function oe_list_pages_form_search_api_index_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
// We need to restrict by form ID here because this function is also called
// via hook_form_BASE_FORM_ID_alter (which is wrong, e.g. in the case of the
// form ID search_api_field_config).
if (!in_array($form_id, [
'search_api_index_form',
'search_api_index_edit_form',
])) {
return;
}
/** @var \Drupal\search_api\IndexInterface $index */
$index = $form_state->getFormObject()->getEntity();
$form['third_party_settings']['oe_list_pages'] = [
'#tree' => TRUE,
'#type' => 'details',
'#title' => t('OpenEuropa List Pages specific index options'),
'#collapsed' => TRUE,
];
$form['third_party_settings']['oe_list_pages']['lists_pages_index'] = [
'#type' => 'checkbox',
'#title' => t('List pages index'),
'#description' => t('Marks the index to be used for list pages. Please note that only one index should be used for this purpose that contain a given entity_type/bundle combination.'),
'#default_value' => $index->getThirdPartySetting('oe_list_pages', 'lists_pages_index', FALSE),
];
}
/**
* Implements template_preprocess_search_api_index().
*/
function oe_list_pages_preprocess_search_api_index(array &$variables) {
/** @var \Drupal\search_api\IndexInterface $index */
$index = $variables['index'];
$variables['table']['#rows'][] = [
'data' => [
[
'header' => TRUE,
'data' => t('List pages index'),
],
$index->getThirdPartySetting('oe_list_pages', 'lists_pages_index', FALSE) ? t('Yes') : t('No'),
],
'class' => ['list-pages-index'],
];
}