diff options
Diffstat (limited to 'modules/book/book.module')
-rw-r--r-- | modules/book/book.module | 143 |
1 files changed, 77 insertions, 66 deletions
diff --git a/modules/book/book.module b/modules/book/book.module index 294076d30..b5790ce4a 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -185,84 +185,95 @@ function book_init() { } /** - * Implementation of hook_block(). + * Implementation of hook_block_list(). + */ +function book_block_list() { + $block = array(); + $block['navigation']['info'] = t('Book navigation'); + $block['navigation']['cache'] = BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_ROLE; + + return $block; +} + +/** + * Implementation of hook_block_view(). * * Displays the book table of contents in a block when the current page is a * single-node view of a book node. */ -function book_block($op = 'list', $delta = '', $edit = array()) { +function book_block_view($delta = '') { $block = array(); - switch ($op) { - case 'list': - $block['navigation']['info'] = t('Book navigation'); - $block['navigation']['cache'] = BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_ROLE; - - return $block; - - case 'view': - $current_bid = 0; - if ($node = menu_get_object()) { - $current_bid = empty($node->book['bid']) ? 0 : $node->book['bid']; - } + $current_bid = 0; + if ($node = menu_get_object()) { + $current_bid = empty($node->book['bid']) ? 0 : $node->book['bid']; + } - if (variable_get('book_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'], $node->book)); - } - 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; - $pseudo_tree[0]['link'] = $book; - $book_menus[$book_id] = menu_tree_output($pseudo_tree); - } - } - $block['content'] = theme('book_all_books_block', $book_menus); + if (variable_get('book_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'], $node->book)); } - elseif ($current_bid) { - // Only display this block when the user is browsing a book. - $select = db_select('node'); - $select->addField('node', 'title'); - $select->condition('nid', $node->book['bid']); - $select->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'], $node->book); - // There should only be one element at the top level. - $data = array_shift($tree); - $block['subject'] = theme('book_title_link', $data['link']); - $block['content'] = ($data['below']) ? menu_tree_output($data['below']) : ''; - } + 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; + $pseudo_tree[0]['link'] = $book; + $book_menus[$book_id] = menu_tree_output($pseudo_tree); } + } + $block['content'] = theme('book_all_books_block', $book_menus); + } + elseif ($current_bid) { + // Only display this block when the user is browsing a book. + $select = db_select('node'); + $select->addField('node', 'title'); + $select->condition('nid', $node->book['bid']); + $select->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'], $node->book); + // There should only be one element at the top level. + $data = array_shift($tree); + $block['subject'] = theme('book_title_link', $data['link']); + $block['content'] = ($data['below']) ? menu_tree_output($data['below']) : ''; + } + } - return $block; + return $block; +} - case 'configure': - $options = array( - 'all pages' => t('Show block on all pages'), - 'book pages' => t('Show block only on book pages'), - ); - $form['book_block_mode'] = array( - '#type' => 'radios', - '#title' => t('Book navigation block display'), - '#options' => $options, - '#default_value' => variable_get('book_block_mode', 'all pages'), - '#description' => t("If <em>Show block on all pages</em> is selected, the block will contain the automatically generated menus for all of the site's books. If <em>Show block only on book pages</em> is selected, the block will contain only the one menu corresponding to the current page's book. In this case, if the current page is not in a book, no block will be displayed. The <em>Page specific visibility settings</em> or other visibility settings can be used in addition to selectively display this block."), - ); +/** + * Implementation of hook_block_configure(). + */ +function book_block_configure($delta = '') { + $block = array(); + $options = array( + 'all pages' => t('Show block on all pages'), + 'book pages' => t('Show block only on book pages'), + ); + $form['book_block_mode'] = array( + '#type' => 'radios', + '#title' => t('Book navigation block display'), + '#options' => $options, + '#default_value' => variable_get('book_block_mode', 'all pages'), + '#description' => t("If <em>Show block on all pages</em> is selected, the block will contain the automatically generated menus for all of the site's books. If <em>Show block only on book pages</em> is selected, the block will contain only the one menu corresponding to the current page's book. In this case, if the current page is not in a book, no block will be displayed. The <em>Page specific visibility settings</em> or other visibility settings can be used in addition to selectively display this block."), + ); - return $form; + return $form; +} - case 'save': - variable_set('book_block_mode', $edit['book_block_mode']); - break; - } +/** + * Implementation of hook_block_save(). + */ +function book_block_save($delta = '', $edit = array()) { + $block = array(); + variable_set('book_block_mode', $edit['book_block_mode']); } /** |