-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathding_news.module
123 lines (109 loc) · 3.14 KB
/
ding_news.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
<?php
/**
* @file
* Create news content type and displays.
*/
include_once 'ding_news.features.inc';
/**
* Implements hook_entity_info_alter().
*/
function ding_news_entity_info_alter(&$entity_info) {
$entity_info['node']['view modes']['teaser_highlight'] = array(
'label' => t('Teaser highlight'),
'custom settings' => TRUE,
);
}
/**
* Implements hook_post_features_revert().
*/
function ding_news_post_features_revert() {
ding_news_install_menu_position('revert');
}
/**
* Implements hook_post_features_disable_feature().
*/
function ding_news_post_features_disable_feature() {
ding_news_install_menu_position('delete');
}
/**
* Implements hook_post_features_enable_feature().
*/
function ding_news_post_features_enable_feature() {
ding_news_install_menu_position('install');
}
/**
* Helper function to install menu position rule.
*/
function ding_news_install_menu_position($op = 'install') {
module_load_include('inc', 'menu_position', 'menu_position.admin');
// Check if rule exists.
$exists = db_select('menu_position_rules', 'mpr')
->fields('mpr', array('rid'))
->condition('admin_title', 'News')
->execute()
->fetchField();
if ($exists && $op == 'revert') {
// The rule exists, so we delete it.
menu_position_delete_rule($exists);
// Activate installation of the rule.
$exists = FALSE;
$op = 'install';
}
if (!$exists && ($op == 'install' || $op == 'revert')) {
// Define conditions.
$conditions = array(
'content_type' => array(
'content_type' => array(
'ding_group' => 'ding_news',
),
),
);
// Find the parent element.
$plid = db_select('menu_links', 'ml')
->fields('ml', array('mlid'))
->condition('link_path', 'nyheder', '=')
->execute()->fetchField();
// Add the rule.
if ($plid) {
menu_position_add_rule(array(
'admin_title' => 'News',
'conditions' => $conditions,
'menu_name' => 'main-menu',
'plid' => $plid,
));
}
else {
watchdog('ding_news', 'Unable to create menu position rule for ding news', array(), WATCHDOG_WARNING);
}
}
if ($exists && $op == 'delete') {
// The rule exists, so we delete it.
menu_position_delete_rule($exists);
}
}
/**
* Implements hook_preprocess_views_view().
*/
function ding_news_preprocess_views_view(&$vars) {
$view = $vars['view'];
// Add a custom view more link for the news list for a group.
// The standard read more link points to standard news list and it does not
// seem to be possible to provide a custom url in another way.
// Adding a link in a footer text field means that the text will not be
// translatable and the url will not be processed using path alias.
if ($view->name = 'ding_news' &&
$view->current_display == 'ding_news_groups_list'
) {
if (!empty($view->result[0]->og_membership_node_gid)) {
$vars['more'] = theme(
'views_more',
array(
'more_url' => url(
'temaer/' . $view->result[0]->og_membership_node_gid . '/nyheder'
),
'link_text' => t('See all news'),
)
);
}
}
}