-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathding_search_collection.module
More file actions
63 lines (56 loc) · 1.76 KB
/
ding_search_collection.module
File metadata and controls
63 lines (56 loc) · 1.76 KB
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
<?php
/**
* @file
* Ding Search Collection.
*/
/**
* Implements hook_entity_view().
*/
function ding_search_collection_entity_view($entity, $entity_type, $view_mode, $langcode) {
// Check that ting_collection has teaser display.
$display_is_teaser = $entity_type == 'ting_collection' && $view_mode == 'teaser';
// Apply only to ting_collection teaser.
if (!$display_is_teaser) {
return;
}
// If for some reason there is no 'entities' property.
if (!isset($entity->entities)) {
return;
}
// Do not show for collections that have 1 item.
if (count($entity->entities) == 1) {
return;
}
$entity->content['#post_render'] = array('ding_search_collection_render');
$entity->content['#attached'] = array(
'css' => array( drupal_get_path('module', 'ding_search_collection') . '/css/ding_search_collection.css'),
);
}
/**
* Implements hook_theme_registry_alter().
*/
function ding_search_collection_theme_registry_alter(&$theme_registry) {
if (!empty($theme_registry['search_result'])) {
$theme_registry['search_result']['process functions'][] = 'ding_search_collection_search_result';
}
}
/**
* Template preprocess callback.
*/
function ding_search_collection_search_result(&$variables) {
drupal_add_css('module', 'ding_search_collection' . 'css/ding_search_collection.css');
// Check if result has collection divs.
if (strpos($variables['snippet'], 'collection-bg-1')) {
$variables['classes'] .= ' ding-search-collection';
}
}
/**
* Post render callback.
*
* Adds collection visuals to search result.
*/
function ding_search_collection_render($children, $elements) {
return '<div class="collection-bg-2"></div>'
. '<div class="collection-bg-1"></div>'
. '<div class="ting-collection-wrapper">' . $children . '</div>';
}