diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 0457488..052eb71 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -32,8 +32,10 @@ function book_help($path, $arg) { $output .= '
' . t("Users with the View printer-friendly books permission can select the printer-friendly version link visible at the bottom of a book page's content to generate a printer-friendly display of the page and all of its subsections.") . '
'; $output .= ''; return $output; + case 'admin/structure/book': return '

' . t('The book module offers a means to organize a collection of related content pages, collectively known as a book. When viewed, this content automatically displays links to adjacent book pages, providing a simple navigation system for creating and reviewing structured content.') . '

'; + case 'node/%/outline': return '

' . t('The outline feature allows you to include pages in the Book hierarchy, as well as move them within the hierarchy or to reorder an entire book.', array('!book' => \Drupal::url('book.render'), '!book-admin' => \Drupal::url('book.admin'))) . '

'; } @@ -115,7 +117,7 @@ function book_permission() { * Implements hook_entity_info(). */ function book_entity_info(&$entity_info) { - /** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */ + // @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[]. $entity_info['node']->setFormClass('book_outline', 'Drupal\book\Form\BookOutlineForm'); } @@ -142,7 +144,7 @@ function book_node_links_alter(array &$node_links, NodeInterface $node, array &$ $links['book_printer'] = array( 'title' => t('Printer-friendly version'), 'href' => 'book/export/html/' . $node->id(), - 'attributes' => array('title' => t('Show a printer-friendly version of this book page and its sub-pages.')) + 'attributes' => array('title' => t('Show a printer-friendly version of this book page and its sub-pages.')), ); } } @@ -201,7 +203,7 @@ function book_admin_paths() { * This list may be used for generating a list of all the books, or for building * the options for a form select. * - * @return + * @return array_book * An array of all books. */ function book_get_books() { @@ -229,7 +231,8 @@ function book_form_node_form_alter(&$form, &$form_state, $form_id) { if ($access) { $form = \Drupal::service('book.manager')->addFormElements($form, $form_state, $node, $account); // Since the "Book" dropdown can't trigger a form submission when - // JavaScript is disabled, add a submit button to do that. book.admin.css hides + // JavaScript is disabled, add a submit button + // to do that. book.admin.css hides. // this button when JavaScript is enabled. $form['book']['pick-book'] = array( '#type' => 'submit', @@ -277,7 +280,7 @@ function book_pick_book_nojs_submit($form, &$form_state) { * This function is called via Ajax when the selected book is changed on a node * or book outline form. * - * @return + * @return select_element * The rendered parent page select element. */ function book_form_update($form, $form_state) { @@ -287,10 +290,10 @@ function book_form_update($form, $form_state) { /** * Gets the book menu tree for a page and returns it as a linear array. * - * @param $book_link + * @param array $book_link * A fully loaded menu link that is part of the book hierarchy. * - * @return + * @return flat_book_link * A linear array of menu links in the order that the links are shown in the * menu, so the previous and next pages are the elements before and after the * element corresponding to the current node. The children of the current node @@ -313,12 +316,12 @@ function book_get_flat_menu($book_link) { /** * Recursively converts a tree of menu links to a flat array. * - * @param $tree + * @param array $tree * A tree of menu links in an array. - * @param $flat + * @param array $flat * A flat array of the menu links from $tree, passed by reference. * - * @see book_get_flat_menu(). + * see book_get_flat_menu(). */ function _book_flatten_menu($tree, &$flat) { foreach ($tree as $data) { @@ -334,10 +337,10 @@ function _book_flatten_menu($tree, &$flat) { /** * Fetches the menu link for the previous page of the book. * - * @param $book_link + * @param array $book_link * A fully loaded menu link that is part of the book hierarchy. * - * @return + * @return menu_link * A fully loaded menu link for the page before the one represented in * $book_link. */ @@ -355,12 +358,14 @@ function book_prev($book_link) { } while ($key && $key != $book_link['mlid']); if ($key == $book_link['mlid']) { - // The previous page in the book may be a child of the previous visible link. + // The previous page in the book may be a child of the previous + // visible link. if ($prev['depth'] == $book_link['depth'] && $prev['has_children']) { // The subtree will have only one link at the top level - get its data. $tree = \Drupal::service('book.manager')->bookMenuSubtreeData($prev); $data = array_shift($tree); - // The link of interest is the last child - iterate to find the deepest one. + // The link of interest is the last child - iterate to find + // the deepest one. while ($data['below']) { $data = end($data['below']); } @@ -376,10 +381,10 @@ function book_prev($book_link) { /** * Fetches the menu link for the next page of the book. * - * @param $book_link + * @param array $book_link * A fully loaded menu link that is part of the book hierarchy. * - * @return + * @return menu_link * A fully loaded menu link for the page after the one represented in * $book_link. */ @@ -387,9 +392,8 @@ function book_next($book_link) { $flat = book_get_flat_menu($book_link); // Assigning the array to $flat resets the array pointer for use with each(). do { - list($key, ) = each($flat); - } - while ($key && $key != $book_link['mlid']); + list($key,) = each($flat); + } while ($key && $key != $book_link['mlid']); if ($key == $book_link['mlid']) { return current($flat); @@ -399,10 +403,10 @@ function book_next($book_link) { /** * Formats the menu links for the child pages of the current page. * - * @param $book_link + * @param array $book_link * A fully loaded menu link that is part of the book hierarchy. * - * @return + * @return html * HTML for the links to the child pages of the current page. */ function book_children($book_link) { @@ -414,9 +418,9 @@ function book_children($book_link) { // Walk through the array until we find the current page. do { $link = array_shift($flat); - } - while ($link && ($link['mlid'] != $book_link['mlid'])); - // Continue though the array and collect the links whose parent is this page. + } while ($link && ($link['mlid'] != $book_link['mlid'])); + // Continue though the array and collect the links + // whose parent is this page. while (($link = array_shift($flat)) && $link['plid'] == $book_link['mlid']) { $data['link'] = $link; $data['below'] = ''; @@ -435,7 +439,7 @@ function book_children($book_link) { * Implements hook_node_load(). */ function book_node_load($nodes) { - $result = db_query("SELECT * FROM {book} b INNER JOIN {menu_links} ml ON b.mlid = ml.mlid WHERE b.nid IN (:nids)", array(':nids' => array_keys($nodes)), array('fetch' => PDO::FETCH_ASSOC)); + $result = db_query("SELECT * FROM {book} b INNER JOIN {menu_links} ml ON b.mlid = ml.mlid WHERE b.nid IN (:nids)", array(':nids' => array_keys($nodes)), array('fetch' => PDO::FETCH_ASSOC)); foreach ($result as $record) { $nodes[$record['nid']]->book = $record; $nodes[$record['nid']]->book['href'] = $record['link_path']; @@ -450,7 +454,7 @@ function book_node_load($nodes) { function book_node_view(EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) { if ($view_mode == 'full') { if (!empty($node->book['bid']) && empty($node->in_preview)) { - $book_navigation = array( '#theme' => 'book_navigation', '#book_link' => $node->book); + $book_navigation = array('#theme' => 'book_navigation', '#book_link' => $node->book); $node->content['book_navigation'] = array( '#markup' => drupal_render($book_navigation), '#weight' => 100, @@ -518,7 +522,7 @@ function book_node_predelete(EntityInterface $node) { if ($node->id() == $node->book['bid']) { // Handle deletion of a top-level post. $result = db_query("SELECT b.nid FROM {menu_links} ml INNER JOIN {book} b on b.mlid = ml.mlid WHERE ml.plid = :plid", array( - ':plid' => $node->book['mlid'] + ':plid' => $node->book['mlid'], )); foreach ($result as $child) { $child_node = node_load($child->id()); @@ -539,7 +543,7 @@ function book_node_predelete(EntityInterface $node) { * Implements hook_node_prepare_form(). */ function book_node_prepare_form(NodeInterface $node, $form_display, $operation, array &$form_state) { - // Get BookManager service + // Get BookManager service. $book_manager = \Drupal::service('book.manager'); // Prepare defaults for the add/edit form. @@ -592,7 +596,7 @@ function book_form_node_delete_confirm_alter(&$form, $form_state) { } /** - * Implements hook_preprocess_HOOK() for block templates. + * Implements hook_preprocess_HOOK(). */ function book_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'book') { @@ -685,7 +689,14 @@ function template_preprocess_book_navigation(&$variables) { $variables['has_links'] = FALSE; // Link variables to filter for values and set state of the flag variable. - $links = array('prev_url', 'prev_title', 'parent_url', 'parent_title', 'next_url', 'next_title'); + $links = array( + 'prev_url', + 'prev_title', + 'parent_url', + 'parent_title', + 'next_url', + 'next_title', + ); foreach ($links as $link) { if (isset($variables[$link])) { // Flag when there is a value. @@ -792,10 +803,10 @@ function book_node_type_update(NodeTypeInterface $type) { * * Do not call when loading a node, since this function may call node_load(). * - * @param $mlid + * @param int $mlid * The menu link ID of the menu item. * - * @return + * @return object * A menu link, with the link translated for rendering and data added from the * {book} table. FALSE if there is an error. */