1
|
<?php
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
10
|
class PanelizerSearchApiAlterCallback extends SearchApiAbstractAlterCallback {
|
11
|
|
12
|
|
13
|
|
14
|
public function supportsIndex(SearchApiIndex $index) {
|
15
|
$panelizer_plugins = panelizer_get_entity_plugins();
|
16
|
if (isset($panelizer_plugins[$index->getEntityType()])) {
|
17
|
$plugin = $panelizer_plugins[$index->getEntityType()];
|
18
|
return !empty($plugin['uses page manager']);
|
19
|
}
|
20
|
}
|
21
|
|
22
|
public function alterItems(array &$items) {
|
23
|
|
24
|
drupal_save_session(FALSE);
|
25
|
|
26
|
|
27
|
|
28
|
$original_user = $GLOBALS['user'];
|
29
|
$GLOBALS['user'] = drupal_anonymous_user();
|
30
|
|
31
|
$entity_type = $this->index->getEntityType();
|
32
|
$entity_handler = panelizer_entity_plugin_get_handler($entity_type);
|
33
|
|
34
|
foreach ($items as &$item) {
|
35
|
$entity_id = entity_id($entity_type, $item);
|
36
|
|
37
|
$item->search_api_panelizer_content = NULL;
|
38
|
$item->search_api_panelizer_title = NULL;
|
39
|
|
40
|
|
41
|
|
42
|
|
43
|
if (isset($item->search_api_language)) {
|
44
|
global $language_content;
|
45
|
$original_language_content = $language_content;
|
46
|
$languages = language_list();
|
47
|
if (isset($languages[$item->search_api_language])) {
|
48
|
$language_content = $languages[$item->search_api_language];
|
49
|
}
|
50
|
else {
|
51
|
$language_content = language_default();
|
52
|
}
|
53
|
}
|
54
|
|
55
|
try {
|
56
|
if ($render_info = $entity_handler->render_entity($item, 'page_manager')) {
|
57
|
$item->search_api_panelizer_content = $render_info['content'];
|
58
|
$item->search_api_panelizer_title = !empty($render_info['title']) ? $render_info['title'] : NULL;
|
59
|
}
|
60
|
}
|
61
|
catch (Exception $e) {
|
62
|
watchdog_exception('panelizer', $e, 'Error indexing Panelizer content for %entity_type with ID %entity_id', array('%entity_type' => $entity_type, '%entity_id' => $entity_id));
|
63
|
}
|
64
|
|
65
|
|
66
|
if (isset($original_language_content)) {
|
67
|
$language_content = $original_language_content;
|
68
|
}
|
69
|
}
|
70
|
|
71
|
|
72
|
$GLOBALS['user'] = $original_user;
|
73
|
drupal_save_session(TRUE);
|
74
|
}
|
75
|
|
76
|
public function propertyInfo() {
|
77
|
return array(
|
78
|
'search_api_panelizer_content' => array(
|
79
|
'label' => t('Panelizer "Full page override" HTML output'),
|
80
|
'description' => t('The whole HTML content of the entity when viewed with Panelizer\'s "Full page override".'),
|
81
|
'type' => 'text',
|
82
|
),
|
83
|
'search_api_panelizer_title' => array(
|
84
|
'label' => t('Panelizer "Full page override" page title'),
|
85
|
'description' => t('The page title of the entity when viewed with Panelizer\'s "Full page override".'),
|
86
|
'type' => 'text',
|
87
|
),
|
88
|
);
|
89
|
}
|
90
|
}
|