diff --git a/core/modules/book/book.install b/core/modules/book/book.install index 0b540bd..33063bc 100644 --- a/core/modules/book/book.install +++ b/core/modules/book/book.install @@ -21,7 +21,7 @@ function book_uninstall() { */ function book_schema() { $schema['book'] = array( - 'description' => 'Stores book outline information. Uniquely connects each node in the outline to a link in {menu_links}', + 'description' => 'Stores book outline information. Uniquely connects each node in the outline to a link in {menu_links}', 'fields' => array( 'mlid' => array( 'type' => 'int', diff --git a/core/modules/book/book.module b/core/modules/book/book.module index f8ab2f5..795b88d 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -33,8 +33,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'))) . '

'; } @@ -146,7 +148,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.')), ); } } @@ -225,7 +227,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 * An array of all books. */ function book_get_books() { @@ -252,9 +254,9 @@ 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 - // this button when JavaScript is enabled. + // 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 this + // button when JavaScript is enabled. $form['book']['pick-book'] = array( '#type' => 'submit', '#value' => t('Change book (update list of parents)'), @@ -300,9 +302,6 @@ 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 - * The rendered parent page select element. */ function book_form_update($form, $form_state) { return $form['book']['plid']; @@ -311,10 +310,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 array * 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 @@ -337,12 +336,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) { @@ -358,10 +357,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 array * A fully loaded menu link for the page before the one represented in * $book_link. */ @@ -379,12 +378,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']); } @@ -400,10 +401,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 array * A fully loaded menu link for the page after the one represented in * $book_link. */ @@ -411,9 +412,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); @@ -423,10 +423,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 string * HTML for the links to the child pages of the current page. */ function book_children($book_link) { @@ -438,9 +438,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'] = ''; @@ -459,7 +459,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']; @@ -474,7 +474,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, @@ -542,7 +542,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()); @@ -563,7 +563,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. @@ -616,7 +616,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') { @@ -709,7 +709,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. @@ -816,12 +823,12 @@ 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 \Drupal\Core\Entity\EntityInterface * A menu link, with the link translated for rendering and data added from the - * {book} table. FALSE if there is an error. + * {book} table. NULL if there is an error. */ function book_link_load($mlid) { return entity_load('menu_link', $mlid); diff --git a/core/modules/book/lib/Drupal/book/BookExport.php b/core/modules/book/lib/Drupal/book/BookExport.php index c86e25c..15b600c 100644 --- a/core/modules/book/lib/Drupal/book/BookExport.php +++ b/core/modules/book/lib/Drupal/book/BookExport.php @@ -35,19 +35,19 @@ class BookExport { /** * Constructs a BookExport object. * - * @param \Drupal\Core\Entity\EntityManagerInterface $entityManager + * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. */ - public function __construct(EntityManagerInterface $entityManager) { - $this->nodeStorage = $entityManager->getStorageController('node'); - $this->viewBuilder = $entityManager->getViewBuilder('node'); + public function __construct(EntityManagerInterface $entity_manager) { + $this->nodeStorage = $entity_manager->getStorageController('node'); + $this->viewBuilder = $entity_manager->getViewBuilder('node'); } /** * Generates HTML for export when invoked by book_export(). * - * The given node is embedded to its absolute depth in a top level section. For - * example, a child node with depth 2 in the hierarchy is contained in + * The given node is embedded to its absolute depth in a top level section. + * For example, a child node with depth 2 in the hierarchy is contained in * (otherwise empty)
elements corresponding to depth 0 and depth 1. * This is intended to support WYSIWYG output - e.g., level 3 sections always * look like level 3 sections, no matter their depth relative to the node diff --git a/core/modules/book/lib/Drupal/book/BookManager.php b/core/modules/book/lib/Drupal/book/BookManager.php index 37982ff..6722715 100644 --- a/core/modules/book/lib/Drupal/book/BookManager.php +++ b/core/modules/book/lib/Drupal/book/BookManager.php @@ -62,17 +62,17 @@ class BookManager { public function __construct(Connection $connection, EntityManagerInterface $entity_manager, TranslationInterface $translation, ConfigFactoryInterface $config_factory) { $this->connection = $connection; $this->entityManager = $entity_manager; - $this->translation = $translation; + $this->translation = $translation; $this->configFactory = $config_factory; } /** * Returns an array of all books. * - * This list may be used for generating a list of all the books, or for building - * the options for a form select. + * 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 * An array of all books. */ public function getAllBooks() { @@ -233,7 +233,8 @@ public function addFormElements(array $form, array &$form_state, NodeInterface $ $options = array(); $nid = !$node->isNew() ? $node->id() : 'new'; if ($node->id() && ($nid == $node->book['original_bid']) && ($node->book['parent_depth_limit'] == 0)) { - // This is the top level node in a maximum depth book and thus cannot be moved. + // This is the top level node in a maximum depth book and thus cannot be + // moved. $options[$node->id()] = $node->label(); } else { @@ -308,14 +309,16 @@ public function updateOutline(NodeInterface $node) { $node->book['link_path'] = 'node/' . $node->id(); $node->book['link_title'] = $node->label(); - $node->book['parent_mismatch'] = FALSE; // The normal case. + // The normal case. + $node->book['parent_mismatch'] = FALSE; if ($node->book['bid'] == $node->id()) { $node->book['plid'] = 0; $node->book['menu_name'] = $this->createMenuName($node->id()); } else { - // Check in case the parent is not is this book; the book takes precedence. + // Check in case the parent is not is this book; the book takes + // precedence. if (!empty($node->book['plid'])) { $parent = $this->connection->query("SELECT * FROM {book} WHERE mlid = :mlid", array( ':mlid' => $node->book['plid'], @@ -325,7 +328,8 @@ public function updateOutline(NodeInterface $node) { $node->book['plid'] = $this->connection->query("SELECT mlid FROM {book} WHERE nid = :nid", array( ':nid' => $node->book['bid'], ))->fetchField(); - $node->book['parent_mismatch'] = TRUE; // Likely when JS is disabled. + // Likely when JS is disabled. + $node->book['parent_mismatch'] = TRUE; } } @@ -358,7 +362,7 @@ public function updateOutline(NodeInterface $node) { return FALSE; } -/** + /** * Translates a string to the current language or to a given language. * * See the t() documentation for details. @@ -370,10 +374,10 @@ protected function t($string, array $args = array(), array $options = array()) { /** * Generates the corresponding menu name from a book ID. * - * @param $id + * @param int $id * The book ID for which to make a menu name. * - * @return + * @return string * The menu name. */ public function createMenuName($id) { @@ -405,8 +409,8 @@ public function updateId($book_link) { /** * Builds the parent selection form element for the node form or outline tab. * - * This function is also called when generating a new set of options during the - * Ajax callback, so an array is returned that can be used to replace an + * This function is also called when generating a new set of options during + * the Ajax callback, so an array is returned that can be used to replace an * existing form element. * * @param array $book_link @@ -459,9 +463,9 @@ protected function addParentSelectFormElements(array $book_link) { * Recursively processes and formats menu items for getTableOfContents(). * * This helper function recursively modifies the table of contents array for - * each item in the menu tree, ignoring items in the exclude array or at a depth - * greater than the limit. Truncates titles over thirty characters and appends - * an indentation string incremented by depth. + * each item in the menu tree, ignoring items in the exclude array or at a + * depth greater than the limit. Truncates titles over thirty characters and + * appends an indentation string incremented by depth. * * @param array $tree * The data structure of the book's menu tree. Includes hidden links. @@ -469,13 +473,14 @@ protected function addParentSelectFormElements(array $book_link) { * A string appended to each menu item title. Increments by '--' per depth * level. * @param array $toc - * Reference to the table of contents array. This is modified in place, so the - * function does not have a return value. + * Reference to the table of contents array. This is modified in place, so + * the function does not have a return value. * @param array $exclude * Optional array of menu link ID values. Any link whose menu link ID is in * this array will be excluded (along with its children). * @param int $depth_limit - * Any link deeper than this value will be excluded (along with its children). + * Any link deeper than this value will be excluded (along with its + * children). */ protected function recurseTableOfContents(array $tree, $indent, array &$toc, array $exclude, $depth_limit) { foreach ($tree as $data) { @@ -499,15 +504,16 @@ protected function recurseTableOfContents(array $tree, $indent, array &$toc, arr * @param int $bid * The ID of the book whose pages are to be listed. * @param int $depth_limit - * Any link deeper than this value will be excluded (along with its children). + * Any link deeper than this value will be excluded (along with its + * children). * @param array $exclude - * (optional) An array of menu link ID values. Any link whose menu link ID is - * in this array will be excluded (along with its children). Defaults to an - * empty array. + * (optional) An array of menu link ID values. Any link whose menu link ID + * is in this array will be excluded (along with its children). Defaults to + * an empty array. * * @return array - * An array of (menu link ID, title) pairs for use as options for selecting a - * book page. + * An array of (menu link ID, title) pairs for use as options for selecting + * a book page. */ public function getTableOfContents($bid, $depth_limit, array $exclude = array()) { $tree = $this->bookTreeAllData($this->createMenuName($bid)); @@ -555,9 +561,11 @@ public function bookTreeAllData($menu_name, $link = NULL, $max_depth = NULL) { $tree = &drupal_static('menu_tree_all_data', array()); $language_interface = language(Language::TYPE_INTERFACE); - // Use $mlid as a flag for whether the data being loaded is for the whole tree. + // Use $mlid as a flag for whether the data being loaded is for the whole + // tree. $mlid = isset($link['mlid']) ? $link['mlid'] : 0; - // Generate a cache ID (cid) specific for this $menu_name, $link, $language, and depth. + // Generate a cache ID (cid) specific for this $menu_name, $link, $language, + // and depth. $cid = 'links:' . $menu_name . ':all:' . $mlid . ':' . $language_interface->id . ':' . (int) $max_depth; if (!isset($tree[$cid])) { @@ -575,8 +583,9 @@ public function bookTreeAllData($menu_name, $link = NULL, $max_depth = NULL) { 'max_depth' => $max_depth, ); if ($mlid) { - // The tree is for a single item, so we need to match the values in its - // p columns and 0 (the top level) with the plid values of other links. + // The tree is for a single item, so we need to match the values in + // its p columns and 0 (the top level) with the plid values of other + // links. $parents = array(0); for ($i = 1; $i < MENU_MAX_DEPTH; $i++) { if (!empty($link["p$i"])) { @@ -685,9 +694,9 @@ public function bookTreeOutput(array $tree) { * The name of the menu. * @param array $parameters * (optional) An associative array of build parameters. Possible keys: - * - expanded: An array of parent link ids to return only menu links that are - * children of one of the plids in this list. If empty, the whole menu tree - * is built, unless 'only_active_trail' is TRUE. + * - expanded: An array of parent link ids to return only menu links that + * are children of one of the plids in this list. If empty, the whole menu + * tree is built, unless 'only_active_trail' is TRUE. * - active_trail: An array of mlids, representing the coordinates of the * currently active menu link. * - only_active_trail: Whether to only return links that are in the active @@ -823,8 +832,8 @@ public function bookTreeCheckAccess(&$tree, $node_links = array()) { $nids = array_keys($node_links); $select = db_select('node_field_data', 'n'); $select->addField('n', 'nid'); - // @todo This should be actually filtering on the desired node status field - // language and just fall back to the default language. + // @todo This should be actually filtering on the desired node status + // field language and just fall back to the default language. $select->condition('n.status', 1); $select->condition('n.nid', $nids, 'IN'); @@ -852,8 +861,9 @@ protected function _menu_tree_check_access(&$tree) { $this->_menu_tree_check_access($tree[$key]['below']); } // The weights are made a uniform 5 digits by adding 50000 as an offset. - // After _menu_link_translate(), $item['title'] has the localized link title. - // Adding the mlid to the end of the index insures that it is unique. + // After _menu_link_translate(), $item['title'] has the localized link + // title. Adding the mlid to the end of the index insures that it is + // unique. $new_tree[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' . $item['mlid']] = $tree[$key]; } } @@ -896,9 +906,9 @@ protected function _menu_link_translate(&$item, $translate = FALSE) { $item['localized_options'] = $item['options']; // All 'class' attributes are assumed to be an array during rendering, but // links stored in the database may use an old string value. - // @todo In order to remove this code we need to implement a database update - // including unserializing all existing link options and running this code - // on them, as well as adding validation to menu_link_save(). + // @todo In order to remove this code we need to implement a database + // update including unserializing all existing link options and running + // this code on them, as well as adding validation to menu_link_save(). if (isset($item['options']['attributes']['class']) && is_string($item['options']['attributes']['class'])) { $item['localized_options']['attributes']['class'] = explode(' ', $item['options']['attributes']['class']); } @@ -911,11 +921,11 @@ protected function _menu_link_translate(&$item, $translate = FALSE) { * * @param array $links * A flat array of menu links that are part of the menu. Each array element - * is an associative array of information about the menu link, containing the - * fields from the {menu_links} table, and optionally additional information - * from the {menu_router} table, if the menu item appears in both tables. - * This array must be ordered depth-first. See _menu_build_tree() for a sample - * query. + * is an associative array of information about the menu link, containing + * the fields from the {menu_links} table, and optionally additional + * information from the {menu_router} table, if the menu item appears in + * both tables. This array must be ordered depth-first. + * See _menu_build_tree() for a sample query. * @param array $parents * An array of the menu link ID values that are in the path from the current * page to the root of the menu tree. @@ -927,10 +937,10 @@ protected function _menu_link_translate(&$item, $translate = FALSE) { * associative array containing: * - link: The menu link item from $links, with additional element * 'in_active_trail' (TRUE if the link ID was in $parents). - * - below: An array containing the sub-tree of this item, where each element - * is a tree item array with 'link' and 'below' elements. This array will be - * empty if the menu item has no items in its sub-tree having a depth - * greater than or equal to $depth. + * - below: An array containing the sub-tree of this item, where each + * element is a tree item array with 'link' and 'below' elements. This + * array will be empty if the menu item has no items in its sub-tree + * having a depth greater than or equal to $depth. */ protected function menu_tree_data(array $links, array $parents = array(), $depth = 1) { // Reverse the array so we can use the more efficient array_pop() function. @@ -955,8 +965,9 @@ protected function _menu_tree_data(&$links, $parents, $depth) { 'link' => $item, 'below' => array(), ); - // Look ahead to the next link, but leave it on the array so it's available - // to other recursive function calls if we return or build a sub-tree. + // Look ahead to the next link, but leave it on the array so it's + // available to other recursive function calls if we return or build a + // sub-tree. $next = end($links); // Check whether the next link is the first in a new sub-tree. if ($next && $next['depth'] > $depth) { @@ -984,7 +995,8 @@ protected function _menu_tree_data(&$links, $parents, $depth) { * A fully loaded menu link. * * @return - * A subtree of menu links in an array, in the order they should be rendered. + * A subtree of menu links in an array, in the order they should be + * rendered. */ public function bookMenuSubtreeData($link) { $tree = &drupal_static(__FUNCTION__, array()); @@ -996,8 +1008,8 @@ public function bookMenuSubtreeData($link) { $cache = cache('menu')->get($cid); if ($cache && isset($cache->data)) { - // If the cache entry exists, it will just be the cid for the actual data. - // This avoids duplication of large amounts of data. + // If the cache entry exists, it will just be the cid for the actual + // data. This avoids duplication of large amounts of data. $cache = cache('menu')->get($cache->data); if ($cache && isset($cache->data)) { @@ -1032,7 +1044,8 @@ public function bookMenuSubtreeData($link) { if (!cache('menu')->get($tree_cid)) { cache('menu')->set($tree_cid, $data); } - // Cache the cid of the (shared) data using the menu and item-specific cid. + // Cache the cid of the (shared) data using the menu and item-specific + // cid. cache('menu')->set($cid, $tree_cid); } // Check access for the current user to each item in the tree. diff --git a/core/modules/book/lib/Drupal/book/Controller/BookController.php b/core/modules/book/lib/Drupal/book/Controller/BookController.php index b9920d2..7a67ba2 100644 --- a/core/modules/book/lib/Drupal/book/Controller/BookController.php +++ b/core/modules/book/lib/Drupal/book/Controller/BookController.php @@ -38,14 +38,14 @@ class BookController implements ContainerInjectionInterface { /** * Constructs a BookController object. * - * @param \Drupal\book\BookManager $bookManager + * @param \Drupal\book\BookManager $book_manager * The book manager. - * @param \Drupal\book\BookExport $bookExport + * @param \Drupal\book\BookExport $book_export * The book export service. */ - public function __construct(BookManager $bookManager, BookExport $bookExport) { - $this->bookManager = $bookManager; - $this->bookExport = $bookExport; + public function __construct(BookManager $book_manager, BookExport $book_export) { + $this->bookManager = $book_manager; + $this->bookExport = $book_export; } /** @@ -63,7 +63,6 @@ public static function create(ContainerInterface $container) { * * @return array * A render array representing the administrative page content. - * */ public function adminOverview() { $rows = array(); diff --git a/core/modules/book/lib/Drupal/book/Form/BookAdminEditForm.php b/core/modules/book/lib/Drupal/book/Form/BookAdminEditForm.php index 07beef0..57c3374 100644 --- a/core/modules/book/lib/Drupal/book/Form/BookAdminEditForm.php +++ b/core/modules/book/lib/Drupal/book/Form/BookAdminEditForm.php @@ -105,7 +105,8 @@ public function validateForm(array &$form, array &$form_state) { */ public function submitForm(array &$form, array &$form_state) { // Save elements in the same order as defined in post rather than the form. - // This ensures parents are updated before their children, preventing orphans. + // This ensures parents are updated before their children, preventing + // orphans. $order = array_flip(array_keys($form_state['input']['table'])); $form['table'] = array_merge($order, $form['table']); diff --git a/core/modules/book/lib/Drupal/book/Form/BookSettingsForm.php b/core/modules/book/lib/Drupal/book/Form/BookSettingsForm.php index 499b70e..b254c12 100644 --- a/core/modules/book/lib/Drupal/book/Form/BookSettingsForm.php +++ b/core/modules/book/lib/Drupal/book/Form/BookSettingsForm.php @@ -78,4 +78,3 @@ public function submitForm(array &$form, array &$form_state) { } } - diff --git a/core/modules/book/lib/Drupal/book/Plugin/Block/BookNavigationBlock.php b/core/modules/book/lib/Drupal/book/Plugin/Block/BookNavigationBlock.php index 456a993..683cd50 100644 --- a/core/modules/book/lib/Drupal/book/Plugin/Block/BookNavigationBlock.php +++ b/core/modules/book/lib/Drupal/book/Plugin/Block/BookNavigationBlock.php @@ -71,9 +71,9 @@ public function defaultConfiguration() { } /** - * Overrides \Drupal\block\BlockBase::blockForm() + * Overrides \Drupal\block\BlockBase::blockForm(). */ - function blockForm($form, &$form_state) { + public function blockForm($form, &$form_state) { $options = array( 'all pages' => t('Show block on all pages'), 'book pages' => t('Show block only on book pages'), @@ -84,7 +84,7 @@ function blockForm($form, &$form_state) { '#options' => $options, '#default_value' => $this->configuration['block_mode'], '#description' => t("If Show block on all pages is selected, the block will contain the automatically generated menus for all of the site's books. If Show block only on book pages 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 Page specific visibility settings or other visibility settings can be used in addition to selectively display this block."), - ); + ); return $form; } @@ -148,7 +148,7 @@ public function build() { $book_title_link = array('#theme' => 'book_title_link', '#link' => $data['link']); return array( '#title' => drupal_render($book_title_link), - $below, + 0 => $below, ); } } diff --git a/core/modules/book/lib/Drupal/book/Tests/BookTest.php b/core/modules/book/lib/Drupal/book/Tests/BookTest.php index 21fc988..a378b0e 100644 --- a/core/modules/book/lib/Drupal/book/Tests/BookTest.php +++ b/core/modules/book/lib/Drupal/book/Tests/BookTest.php @@ -33,24 +33,27 @@ class BookTest extends WebTestBase { /** * A user with permission to create and edit books. * - * @var object + * @var \Drupal\Core\Session\AccountInterface */ - protected $book_author; + protected $bookAuthor; /** * A user with permission to view a book and access printer-friendly version. * - * @var object + * @var \Drupal\Core\Session\AccountInterface */ - protected $web_user; + protected $webUser; /** * A user with permission to create and edit books and to administer blocks. * * @var object */ - protected $admin_user; + protected $adminUser; + /** + * {@inheritdoc} + */ public static function getInfo() { return array( 'name' => 'Book functionality', @@ -59,24 +62,27 @@ public static function getInfo() { ); } - function setUp() { + /** + * Adds required users after setting up the Drupal site. + */ + public function setUp() { parent::setUp(); // node_access_test requires a node_access_rebuild(). node_access_rebuild(); // Create users. - $this->book_author = $this->drupalCreateUser(array('create new books', 'create book content', 'edit own book content', 'add content to books')); - $this->web_user = $this->drupalCreateUser(array('access printer-friendly version', 'node test view')); - $this->admin_user = $this->drupalCreateUser(array('create new books', 'create book content', 'edit own book content', 'add content to books', 'administer blocks', 'administer permissions', 'administer book outlines', 'node test view', 'administer content types', 'administer site configuration')); + $this->bookAuthor = $this->drupalCreateUser(array('create new books', 'create book content', 'edit own book content', 'add content to books')); + $this->webUser = $this->drupalCreateUser(array('access printer-friendly version', 'node test view')); + $this->adminUser = $this->drupalCreateUser(array('create new books', 'create book content', 'edit own book content', 'add content to books', 'administer blocks', 'administer permissions', 'administer book outlines', 'node test view', 'administer content types', 'administer site configuration')); } /** * Creates a new book with a page hierarchy. */ - function createBook() { + public function createBook() { // Create new book. - $this->drupalLogin($this->book_author); + $this->drupalLogin($this->bookAuthor); $this->book = $this->createBookNode('new'); $book = $this->book; @@ -91,11 +97,16 @@ function createBook() { * |- Node 4 */ $nodes = array(); - $nodes[] = $this->createBookNode($book->id()); // Node 0. - $nodes[] = $this->createBookNode($book->id(), $nodes[0]->book['mlid']); // Node 1. - $nodes[] = $this->createBookNode($book->id(), $nodes[0]->book['mlid']); // Node 2. - $nodes[] = $this->createBookNode($book->id()); // Node 3. - $nodes[] = $this->createBookNode($book->id()); // Node 4. + // Node 0. + $nodes[] = $this->createBookNode($book->id()); + // Node 1. + $nodes[] = $this->createBookNode($book->id(), $nodes[0]->book['mlid']); + // Node 2. + $nodes[] = $this->createBookNode($book->id(), $nodes[0]->book['mlid']); + // Node 3. + $nodes[] = $this->createBookNode($book->id()); + // Node 4. + $nodes[] = $this->createBookNode($book->id()); $this->drupalLogout(); @@ -105,12 +116,12 @@ function createBook() { /** * Tests book functionality through node interfaces. */ - function testBook() { + public function testBook() { // Create new book. $nodes = $this->createBook(); $book = $this->book; - $this->drupalLogin($this->web_user); + $this->drupalLogin($this->webUser); // Check that book pages display along with the correct outlines and // previous/next links. @@ -124,14 +135,14 @@ function testBook() { $this->drupalLogout(); // Create a second book, and move an existing book page into it. - $this->drupalLogin($this->book_author); + $this->drupalLogin($this->bookAuthor); $other_book = $this->createBookNode('new'); $node = $this->createBookNode($book->id()); $edit = array('book[bid]' => $other_book->id()); $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save')); $this->drupalLogout(); - $this->drupalLogin($this->web_user); + $this->drupalLogin($this->webUser); // Check that the nodes in the second book are displayed correctly. // First we must set $this->book to the second book, so that the @@ -157,9 +168,9 @@ function testBook() { * @param $next * (optional) Next link node. Defaults to FALSE. * @param array $breadcrumb - * The nodes that should be displayed in the breadcrumb. + * (optional) The nodes that should be displayed in the breadcrumb. */ - function checkBookNode(EntityInterface $node, $nodes, $previous = FALSE, $up = FALSE, $next = FALSE, array $breadcrumb) { + public function checkBookNode(EntityInterface $node, $nodes, $previous = FALSE, $up = FALSE, $next = FALSE, array $breadcrumb = array()) { // $number does not use drupal_static as it should not be reset // since it uniquely identifies each call to checkBookNode(). static $number = 0; @@ -175,15 +186,15 @@ function checkBookNode(EntityInterface $node, $nodes, $previous = FALSE, $up = F // Check previous, up, and next links. if ($previous) { - $this->assertRaw(l(' ' . $previous->label(), 'node/' . $previous->id(), array('html' => TRUE, 'attributes' => array('rel' => array('prev'), 'title' => t('Go to previous page')))), 'Previous page link found.'); + $this->assertRaw(l(t(' @label', array('@label' => $previous->label())), 'node/' . $previous->id(), array('html' => TRUE, 'attributes' => array('rel' => array('prev'), 'title' => t('Go to previous page')))), 'Previous page link found.'); } if ($up) { - $this->assertRaw(l('Up', 'node/' . $up->id(), array('html'=> TRUE, 'attributes' => array('title' => t('Go to parent page')))), 'Up page link found.'); + $this->assertRaw(l(t('Up'), 'node/' . $up->id(), array('html' => TRUE, 'attributes' => array('title' => t('Go to parent page')))), 'Up page link found.'); } if ($next) { - $this->assertRaw(l($next->label() . ' ', 'node/' . $next->id(), array('html'=> TRUE, 'attributes' => array('rel' => array('next'), 'title' => t('Go to next page')))), 'Next page link found.'); + $this->assertRaw(l(t('@label ', array('@label' => $next->label())), 'node/' . $next->id(), array('html' => TRUE, 'attributes' => array('rel' => array('next'), 'title' => t('Go to next page')))), 'Next page link found.'); } // Compute the expected breadcrumb. @@ -220,7 +231,7 @@ function checkBookNode(EntityInterface $node, $nodes, $previous = FALSE, $up = F * @return string * A regular expression that locates sub-nodes of the outline. */ - function generateOutlinePattern($nodes) { + public function generateOutlinePattern($nodes) { $outline = ''; foreach ($nodes as $node) { $outline .= '(node\/' . $node->id() . ')(.*?)(' . $node->label() . ')(.*?)'; @@ -236,11 +247,15 @@ function generateOutlinePattern($nodes) { * A book node ID or set to 'new' to create a new book. * @param int|null $parent * (optional) Parent book reference ID. Defaults to NULL. + * + * @return \Drupal\node\NodeInterface + * The created book node object. */ - function createBookNode($book_nid, $parent = NULL) { + public function createBookNode($book_nid, $parent = NULL) { // $number does not use drupal_static as it should not be reset // since it uniquely identifies each call to createBookNode(). - static $number = 0; // Used to ensure that when sorted nodes stay in same order. + // Used to ensure that when sorted nodes stay in same order. + static $number = 0; $edit = array(); $edit['title[0][value]'] = $number . ' - SimpleTest test node ' . $this->randomName(10); @@ -268,12 +283,12 @@ function createBookNode($book_nid, $parent = NULL) { /** * Tests book export ("printer-friendly version") functionality. */ - function testBookExport() { + public function testBookExport() { // Create a book. $nodes = $this->createBook(); // Login as web user and view printer-friendly version. - $this->drupalLogin($this->web_user); + $this->drupalLogin($this->webUser); $this->drupalGet('node/' . $this->book->id()); $this->clickLink(t('Printer-friendly version')); @@ -313,8 +328,8 @@ function testBookExport() { /** * Tests the functionality of the book navigation block. */ - function testBookNavigationBlock() { - $this->drupalLogin($this->admin_user); + public function testBookNavigationBlock() { + $this->drupalLogin($this->adminUser); // Enable the block. $block = $this->drupalPlaceBlock('book_navigation'); @@ -336,8 +351,8 @@ function testBookNavigationBlock() { /** * Tests the book navigation block when an access module is enabled. */ - function testNavigationBlockOnAccessModuleEnabled() { - $this->drupalLogin($this->admin_user); + public function testNavigationBlockOnAccessModuleEnabled() { + $this->drupalLogin($this->adminUser); $block = $this->drupalPlaceBlock('book_navigation', array('block_mode' => 'book pages')); // Give anonymous users the permission 'node test view'. @@ -350,7 +365,7 @@ function testNavigationBlockOnAccessModuleEnabled() { $this->createBook(); // Test correct display of the block to registered users. - $this->drupalLogin($this->web_user); + $this->drupalLogin($this->webUser); $this->drupalGet('node/' . $this->book->id()); $this->assertText($block->label(), 'Book navigation block is displayed to registered users.'); $this->drupalLogout(); @@ -367,33 +382,32 @@ function testNavigationBlockOnAccessModuleEnabled() { /** * Tests the access for deleting top-level book nodes. */ - function testBookDelete() { - $nodes = $this->createBook(); - $this->drupalLogin($this->admin_user); - $edit = array(); - - // Test access to delete top-level and child book nodes. - $this->drupalGet('node/' . $this->book->id() . '/outline/remove'); - $this->assertResponse('403', 'Deleting top-level book node properly forbidden.'); - $this->drupalPostForm('node/' . $nodes[4]->id() . '/outline/remove', $edit, t('Remove')); - $node4 = node_load($nodes[4]->id(), TRUE); - $this->assertTrue(empty($node4->book), 'Deleting child book node properly allowed.'); - - // Delete all child book nodes and retest top-level node deletion. - foreach ($nodes as $node) { - $nids[] = $node->id(); - } - entity_delete_multiple('node', $nids); - $this->drupalPostForm('node/' . $this->book->id() . '/outline/remove', $edit, t('Remove')); - $node = node_load($this->book->id(), TRUE); - $this->assertTrue(empty($node->book), 'Deleting childless top-level book node properly allowed.'); - } - - /* + public function testBookDelete() { + $nodes = $this->createBook(); + $this->drupalLogin($this->adminUser); + $edit = array(); + + // Test access to delete top-level and child book nodes. + $this->drupalGet('node/' . $this->book->id() . '/outline/remove'); + $this->assertResponse('403', 'Deleting top-level book node properly forbidden.'); + $this->drupalPostForm('node/' . $nodes[4]->id() . '/outline/remove', $edit, t('Remove')); + $node4 = node_load($nodes[4]->id(), TRUE); + $this->assertTrue(empty($node4->book), 'Deleting child book node properly allowed.'); + // Delete all child book nodes and retest top-level node deletion. + foreach ($nodes as $node) { + $nids[] = $node->id(); + } + entity_delete_multiple('node', $nids); + $this->drupalPostForm('node/' . $this->book->id() . '/outline/remove', $edit, t('Remove')); + $node = node_load($this->book->id(), TRUE); + $this->assertTrue(empty($node->book), 'Deleting childless top-level book node properly allowed.'); + } + + /** * Tests node type changing machine name when type is a book allowed type. */ - function testBookNodeTypeChange() { - $this->drupalLogin($this->admin_user); + public function testBookNodeTypeChange() { + $this->drupalLogin($this->adminUser); // Change the name, machine name and description. $edit = array( 'name' => 'Bar', @@ -490,7 +504,7 @@ public function testBookOrdering() { $this->createBook(); $book = $this->book; - $this->drupalLogin($this->admin_user); + $this->drupalLogin($this->adminUser); $node1 = $this->createBookNode($book->id()); $node2 = $this->createBookNode($book->id()); $plid = $node1->book['mlid']; @@ -515,10 +529,10 @@ public function testBookOrdering() { */ public function testBookOutline() { // Create new book. - $this->drupalLogin($this->book_author); + $this->drupalLogin($this->bookAuthor); $book = $this->createBookNode('new'); - $this->drupalLogin($this->admin_user); + $this->drupalLogin($this->adminUser); $this->drupalGet('node/' . $book->id() . '/outline'); $this->assertRaw(t('Book outline')); } diff --git a/core/modules/book/tests/Drupal/book/Tests/Menu/BookLocalTasksTest.php b/core/modules/book/tests/Drupal/book/Tests/Menu/BookLocalTasksTest.php index 86492c4..6a80adb 100644 --- a/core/modules/book/tests/Drupal/book/Tests/Menu/BookLocalTasksTest.php +++ b/core/modules/book/tests/Drupal/book/Tests/Menu/BookLocalTasksTest.php @@ -17,6 +17,9 @@ */ class BookLocalTasksTest extends LocalTaskIntegrationTest { + /** + * {@inheritdoc} + */ public static function getInfo() { return array( 'name' => 'Book local tasks test', @@ -25,6 +28,9 @@ public static function getInfo() { ); } + /** + * Adds the required module directories before setting up the Drupal site. + */ public function setUp() { $this->directoryList = array( 'book' => 'core/modules/book', @@ -62,7 +68,7 @@ public function getBookAdminRoutes() { */ public function testBookNodeLocalTasks($route) { $this->assertLocalTasks($route, array( - 0 => array('book.outline', 'node.view', 'node.page_edit', 'node.delete_confirm', 'node.revision_overview',), + 0 => array('book.outline', 'node.view', 'node.page_edit', 'node.delete_confirm', 'node.revision_overview'), )); }