function book_explorer_block_book_explorer_view in Book Explorer 7
1 call to book_explorer_block_book_explorer_view()
- book_explorer_block_view in ./
book_explorer.module - Implements hook_block_view().
File
- ./
book_explorer.module, line 51
Code
function book_explorer_block_book_explorer_view() {
$block = array();
$current_bid = 0;
if ($node = menu_get_object()) {
$current_bid = empty($node->book['bid']) ? 0 : $node->book['bid'];
}
if (variable_get('book_explorer_block_mode', 'all pages') == 'all pages') {
$block['subject'] = t('Book navigation');
$book_menus = array();
$pseudo_tree = array(
0 => array(
'below' => FALSE,
),
);
foreach (book_get_books() as $book_id => $book) {
if ($book['bid'] == $current_bid) {
// If the current page is a node associated with a book, the menu
// needs to be retrieved.
$book_menus[$book_id] = menu_tree_output(menu_tree_all_data($node->book['menu_name']));
}
else {
// Since we know we will only display a link to the top node, there
// is no reason to run an additional menu tree query for each book.
$book['in_active_trail'] = FALSE;
// Check whether user can access the book link.
$book_node = node_load($book['nid']);
$book['access'] = node_access('view', $book_node);
$book_menus[$book_id] = menu_tree_output(menu_tree_all_data($book_node->book['menu_name']));
}
}
$book_menus['#theme'] = 'book_all_books_block';
$block['content'] = $book_menus;
}
elseif ($current_bid) {
// Only display this block when the user is browsing a book.
$select = db_select('node', 'n')
->fields('n', array(
'title',
))
->condition('n.nid', $node->book['bid'])
->addTag('node_access');
$title = $select
->execute()
->fetchField();
// Only show the block if the user has view access for the top-level node.
if ($title) {
$tree = menu_tree_all_data($node->book['menu_name']);
// There should only be one element at the top level.
$data = array_shift($tree);
$block['subject'] = theme('book_title_link', array(
'link' => $data['link'],
));
$block['content'] = $data['below'] ? menu_tree_output($data['below']) : '';
}
}
if (!empty($block['content'])) {
// Move block content down one level so we can wrap a div around it
$block['content'] = array(
'prefix' => array(
'#markup' => '<div class="book-explorer">',
),
'build' => $block['content'],
'suffix' => array(
'#markup' => '</div>',
),
);
// Attach css and js which implements the 'explorer' behaviour
$dir = drupal_get_path('module', 'book_explorer');
$block['content']['build']['#attached']['css'] = array(
$dir . '/book_explorer.css',
);
$block['content']['build']['#attached']['js'] = array(
$dir . '/book_explorer.js',
);
}
return $block;
}