This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dkan_featured_topics.module
65 lines (60 loc) · 1.94 KB
/
dkan_featured_topics.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
<?php
/**
* @file
* Code for the DKAN Featured Topics feature.
*/
include_once 'dkan_featured_topics.features.inc';
/**
* Implements hook_page_alter().
*/
function dkan_featured_topics_page_alter(&$page) {
drupal_add_css(drupal_get_path('module', 'dkan_featured_topics') . '/dkan_featured_topics.css');
}
/**
* Implements hook_theme_registry_alter().
*/
function dkan_featured_topics_theme_registry_alter(&$theme_registry) {
$theme_registry['menu_link__main_menu']['function'] = 'dkan_featured_topics_main_menu';
$theme_registry['menu_link__main_menu']['render element'] = 'element';
$theme_registry['menu_link__main_menu']['theme path'] = drupal_get_path('module', 'dkan_featured_topics');
}
/**
* Overrides theme_main_menu() to add topics dropdown.
*/
function dkan_featured_topics_main_menu($variables) {
$output = "<li class='leaf menu-link-topics featured-topics-menu'>";
if ($variables['element']['#title'] == t('Topics')) {
$link = ($variables['element']['#href'] == '<front>') ? '/' : $variables['element']['#href'];
$output .= '<a href="' . $link . '" class="dropdown-toggle" data-toggle="dropdown" data-target="#"> ' . $variables['element']["#title"] . '<b class="caret"></b></a>';
$output .= views_embed_view('dkan_topics_featured', 'block_1');
}
else {
return theme('menu_link', $variables);
}
$output .= '</li>';
return $output;
}
/**
* Adds "Topics" to main menu.
*/
function dkan_featured_topics_add_menu() {
$main_menu = menu_load_links('main-menu');
$topics_enabled = variable_get('dkan_featured_topics_menu_item_enabled', TRUE);
foreach ($main_menu as $link) {
if ($link['link_title'] == t('Topics')) {
$topics_enabled = TRUE;
break;
}
}
if (!$topics_enabled) {
$item = array(
'link_path' => '<front>',
'link_title' => t('Topics'),
'menu_name' => 'main-menu',
'weight' => 0,
'plid' => 0,
'module' => 'menu',
);
menu_link_save($item);
}
}