forked from ymcatwincities/openy_activity_finder
-
Notifications
You must be signed in to change notification settings - Fork 14
/
openy_activity_finder.module
162 lines (151 loc) · 4.53 KB
/
openy_activity_finder.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* @file
* Contains openy_activity_finder module hooks.
*/
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\NodeInterface;
use Drupal\openy_activity_finder\OpenyActivityFinderSolrBackend;
use Drupal\search_api\IndexInterface;
/**
* Implements hook_theme().
*/
function openy_activity_finder_theme() {
return [
'openy_activity_finder_program_search' => [
'variables' => [
'data' => [],
'ages' => [],
'days' => [],
'categories' => [],
'categories_type' => '',
'activities' => [],
'locations' => [],
'is_search_box_disabled' => '',
'expanderSectionsConfig' => [],
],
],
'openy_camp_finder_program_search' => [
'variables' => [
'data' => [],
'ages' => [],
'weeks' => [],
'categories' => [],
'categories_type' => '',
'activities' => [],
'locations' => [],
'is_search_box_disabled' => '',
],
],
'openy_activity_finder_program_search_page' => [
'variables' => [
'locations' => [],
'categories' => [],
'categories_type' => '',
'ages' => [],
'days' => [],
'weeks' => [],
'is_search_box_disabled' => '',
'is_spots_available_disabled' => '',
'expanderSectionsConfig' => [],
'sort_options' => [],
],
],
'openy_activity_finder_4_block' => [
'variables' => [
'backend_service' => '',
'label' => '',
'label_display' => TRUE,
'ages' => [],
'days' => [],
'times' => [],
'days_times' => [],
'weeks' => [],
'categories' => [],
'start_months' => [],
'durations' => [],
'categories_type' => '',
'activities' => [],
'locations' => [],
'disable_search_box' => FALSE,
'disable_spots_available' => FALSE,
'sort_options' => [],
'default_sort_option' => '',
'relevance_sort_option' => '',
'filters_section_config' => [],
'limit_by_category' => [],
'exclude_by_category' => [],
'limit_by_location' => [],
'exclude_by_location' => [],
'legacy_mode' => FALSE,
'weeks_filter' => FALSE,
'hide_home_branch_block' => FALSE,
'background_image' => [],
'bs_version' => NULL,
'in_memberships_filter' => FALSE,
'start_month_filter' => FALSE,
'duration_filter' => FALSE,
'skip_wizard' => FALSE,
],
],
];
}
/**
* Implements hook_entity_insert().
*/
function openy_activity_finder_entity_insert(EntityInterface $entity) {
_openy_activity_finder_invalidate_cache($entity);
}
/**
* Implements hook_entity_update().
*/
function openy_activity_finder_entity_update(EntityInterface $entity) {
_openy_activity_finder_invalidate_cache($entity);
}
/**
* Implements hook_entity_delete().
*/
function openy_activity_finder_entity_delete(EntityInterface $entity) {
_openy_activity_finder_invalidate_cache($entity);
}
/**
* Helper function for Activity Finder cache invalidation.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
*/
function _openy_activity_finder_invalidate_cache($entity) {
if ($entity->getEntityTypeId() != 'node') {
return;
}
$bundle = $entity->bundle();
if (!in_array($bundle, ['program_subcategory', 'branch', 'camp', 'facility'])) {
return;
}
// Invalidate activity finder cache.
Cache::invalidateTags([OpenyActivityFinderSolrBackend::ACTIVITY_FINDER_CACHE_TAG]);
}
/**
* Implements hook_search_api_solr_field_mapping_alter().
*/
function openy_activity_finder_search_api_solr_field_mapping_alter(IndexInterface $index, array &$fields) {
if (isset($fields['af_time_of_day'])) {
// We can sort only by single value fields.
// @see https://www.drupal.org/project/search_api_solr/issues/2906905
$fields['af_time_of_day'] = 'ds_af_time_of_day';
}
if (isset($fields['af_date_of_day'])) {
// We can sort only by single value fields.
// @see https://www.drupal.org/project/search_api_solr/issues/2906905
$fields['af_date_of_day'] = 'ds_af_date_of_day';
}
}
/**
* Implements hook_activity_finder_program_process_results_alter().
*/
function openy_activity_finder_activity_finder_program_process_results_alter(array &$data, NodeInterface $entity) {
// Add min/max age values (in months).
$data['min_age'] = $entity->field_session_min_age->value;
$data['max_age'] = $entity->field_session_max_age->value;
$data['product_id'] = $entity->field_productid->value;
}