1
|
<?php
|
2
|
|
3
|
if (module_exists('book')) {
|
4
|
/**
|
5
|
* Plugins are described by creating a $plugin array which will be used
|
6
|
* by the system that includes this file.
|
7
|
*/
|
8
|
$plugin = array(
|
9
|
'single' => TRUE,
|
10
|
'title' => t('Book navigation menu'),
|
11
|
'icon' => '../block/icon_core_block_menu.png',
|
12
|
'description' => t('The book menu belonging to the current book node.'),
|
13
|
'required context' => new ctools_context_required(t('Node'), 'node'),
|
14
|
'category' => t('Node'),
|
15
|
);
|
16
|
}
|
17
|
|
18
|
function ctools_node_book_menu_content_type_render($subtype, $conf, $panel_args, $context) {
|
19
|
$node = isset($context->data) ? clone($context->data) : NULL;
|
20
|
$block = new stdClass();
|
21
|
$block->module = 'book_menu';
|
22
|
|
23
|
if ($conf['override_title']) {
|
24
|
$block->title = t($conf['override_title_text']);
|
25
|
}
|
26
|
else {
|
27
|
$block->title = t('Book navigation menu');
|
28
|
}
|
29
|
if ($node) {
|
30
|
$block->delta = $node->nid;
|
31
|
// TODO: the value is not available somehow?!?
|
32
|
$book_block_mode = isset($conf['book_block_mode']) ? $conf['book_block_mode'] : 'book pages';
|
33
|
|
34
|
// Code below is taken from function book_block_view().
|
35
|
$current_bid = empty($node->book['bid']) ? 0 : $node->book['bid'];
|
36
|
|
37
|
if ($book_block_mode === 'all pages') {
|
38
|
$block->subject = t('Book navigation');
|
39
|
$book_menus = array();
|
40
|
$pseudo_tree = array(0 => array('below' => FALSE));
|
41
|
foreach (book_get_books() as $book_id => $book) {
|
42
|
if ($book['bid'] === $current_bid) {
|
43
|
// If the current page is a node associated with a book, the menu
|
44
|
// needs to be retrieved.
|
45
|
$book_menus[$book_id] = menu_tree_output(menu_tree_all_data($node->book['menu_name'], $node->book));
|
46
|
}
|
47
|
else {
|
48
|
// Since we know we will only display a link to the top node, there
|
49
|
// is no reason to run an additional menu tree query for each book.
|
50
|
$book['in_active_trail'] = FALSE;
|
51
|
// Check whether user can access the book link.
|
52
|
$book_node = node_load($book['nid']);
|
53
|
$book['access'] = node_access('view', $book_node);
|
54
|
$pseudo_tree[0]['link'] = $book;
|
55
|
$book_menus[$book_id] = menu_tree_output($pseudo_tree);
|
56
|
}
|
57
|
}
|
58
|
$book_menus['#theme'] = 'book_all_books_block';
|
59
|
$block->content = $book_menus;
|
60
|
}
|
61
|
elseif ($current_bid) {
|
62
|
// Only display this block when the user is browsing a book.
|
63
|
$select = db_select('node', 'n')
|
64
|
->fields('n', array('title'))
|
65
|
->condition('n.nid', $node->book['bid'])
|
66
|
->addTag('node_access');
|
67
|
$title = $select->execute()->fetchField();
|
68
|
// Only show the block if the user has view access for the top-level node.
|
69
|
if ($title) {
|
70
|
$tree = menu_tree_all_data($node->book['menu_name'], $node->book);
|
71
|
// There should only be one element at the top level.
|
72
|
$data = array_shift($tree);
|
73
|
// TODO: subject is not rendered
|
74
|
$block->subject = theme('book_title_link', array('link' => $data['link']));
|
75
|
$block->content = ($data['below']) ? menu_tree_output($data['below']) : '';
|
76
|
}
|
77
|
}
|
78
|
}
|
79
|
else {
|
80
|
$block->content = t('Book navigation pager goes here.');
|
81
|
$block->delta = 'unknown';
|
82
|
}
|
83
|
|
84
|
return $block;
|
85
|
}
|
86
|
|
87
|
function ctools_node_book_menu_content_type_admin_title($subtype, $conf, $context) {
|
88
|
return t('"@s" book navigation pager', array('@s' => $context->identifier));
|
89
|
}
|
90
|
|
91
|
function ctools_node_book_menu_content_type_edit_form($form, &$form_state) {
|
92
|
// Grab block form from the book module.
|
93
|
$block_form = book_block_configure($delta = '');
|
94
|
// TODO: this does not work yet.
|
95
|
// See TODO in: ctools_node_book_menu_content_type_render
|
96
|
if (isset($form_state['input']['book_block_mode'])) {
|
97
|
$block_form['book_block_mode']['#default_value'] = $form_state['input']['book_block_mode'];
|
98
|
}
|
99
|
$form += $block_form;
|
100
|
return $form;
|
101
|
}
|