-
Notifications
You must be signed in to change notification settings - Fork 2
/
cambridge_teasers.module
76 lines (66 loc) · 2.36 KB
/
cambridge_teasers.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
<?php
/**
* @file
* Code for the Teasers feature.
*/
/**
* Implements hook_entity_info_alter().
*/
function cambridge_teasers_entity_info_alter(&$entity_info) {
if (isset($entity_info['node']['view modes']['teaser'])) {
$entity_info['node']['view modes']['teaser']['label'] = 'Horizontal Teaser';
}
$entity_info['node']['view modes'] += array(
'vertical_teaser' => array(
'label' => t('Vertical Teaser'),
'custom settings' => TRUE,
),
'sidebar_teaser' => array(
'label' => t('Sidebar Teaser'),
'custom settings' => TRUE,
),
'focus_on_teaser' => array(
'label' => t('Focus On Teaser'),
'custom settings' => TRUE,
),
'news_listing_item' => array(
'label' => t('News Listing Item'),
'custom settings' => TRUE,
),
);
}
/**
* Implements hook_theme_registry_alter().
*/
function cambridge_teasers_theme_registry_alter(&$theme_registry) {
$module_path = drupal_get_path('module', 'cambridge_teasers') . '/templates';
_theme_process_registry($theme_registry, 'phptemplate', 'theme_engine', 'cambridge_teasers', $module_path);
}
/**
* Implements template_preprocess_node().
*/
function cambridge_teasers_preprocess_node(&$vars) {
$view_modes = array('teaser', 'vertical_teaser', 'sidebar_teaser', 'focus_on_teaser', 'news_listing_item');
if (in_array($vars['view_mode'], $view_modes)) {
$vars['theme_hook_suggestions'][] = 'node____' . $vars['view_mode'];
$vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode'];
$vars['theme_hook_suggestions'][] = 'node__' . $vars['nid'] . '__' . $vars['view_mode'];
$vars['date'] = format_date($vars['node']->created, 'custom', 'j F Y');
}
}
/**
* Implements template_preprocess_field().
*/
function cambridge_teasers_preprocess_field(&$vars) {
$view_modes = array('teaser', 'vertical_teaser', 'sidebar_teaser', 'news_listing_item');
if (in_array($vars['element']['#view_mode'], $view_modes)
&& isset($vars['element']['#formatter'])
&& 'smart_trim_format' === $vars['element']['#formatter']) {
foreach ($vars['items'] as $key => $value) {
if (FALSE === strpos($vars['items'][$key]['#markup'], '<')) {
// Wrap smart-trimmed text that has stripped HTML in a paragraph element.
$vars['items'][$key]['#markup'] = '<p>' . $vars['items'][$key]['#markup'] . '</p>';
}
}
}
}