diff --git a/core/modules/book/book.module b/core/modules/book/book.module index e2f571e..e118467 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -5,6 +5,7 @@ * Allows users to create and organize related content in an outline. */ +use Drupal\book\BookManagerInterface; use Drupal\Component\Utility\String; use Drupal\Core\Entity\EntityInterface; use Drupal\node\NodeInterface; @@ -355,7 +356,7 @@ function book_prev($book_link) { } while ($key && $key != $book_link['nid']); if ($key == $book_link['nid']) { - /** @var \Drupal\book\BookManager $book_manager */ + /** @var BookManagerInterface $book_manager */ $book_manager = \Drupal::service('book.manager'); // The previous page in the book may be a child of the previous visible link. if ($prev['depth'] == $book_link['depth']) { @@ -517,7 +518,7 @@ function book_node_update(EntityInterface $node) { */ function book_node_predelete(EntityInterface $node) { if (!empty($node->book['bid'])) { - /** @var \Drupal\book\BookManager $book_manager */ + /** @var BookManagerInterface $book_manager */ $book_manager = \Drupal::service('book.manager'); $book_manager->deleteFromBook($node->book['nid']); } @@ -645,7 +646,7 @@ function template_preprocess_book_navigation(&$variables) { $variables['prev_title'] = String::checkPlain($prev['title']); } - /** @var \Drupal\book\BookManager $book_manager */ + /** @var BookManagerInterface $book_manager */ $book_manager = \Drupal::service('book.manager'); if ($book_link['pid'] && $parent = $book_manager->loadBookLink($book_link['pid'])) { $parent_href = \Drupal::url('node.view', array('node' => $book_link['pid'])); diff --git a/core/modules/book/lib/Drupal/book/Access/BookNodeIsRemovableAccessCheck.php b/core/modules/book/lib/Drupal/book/Access/BookNodeIsRemovableAccessCheck.php index 7b12219..9477a76 100644 --- a/core/modules/book/lib/Drupal/book/Access/BookNodeIsRemovableAccessCheck.php +++ b/core/modules/book/lib/Drupal/book/Access/BookNodeIsRemovableAccessCheck.php @@ -8,6 +8,7 @@ namespace Drupal\book\Access; use Drupal\book\BookManager; +use Drupal\book\BookManagerInterface; use Drupal\Core\Routing\Access\AccessInterface; use Drupal\Core\Session\AccountInterface; use Symfony\Component\Routing\Route; @@ -21,17 +22,17 @@ class BookNodeIsRemovableAccessCheck implements AccessInterface { /** * Book Manager Service. * - * @var \Drupal\book\BookManager + * @var BookManagerInterface */ protected $bookManager; /** * Constructs a BookNodeIsRemovableAccessCheck object. * - * @param \Drupal\book\BookManager $book_manager + * @param BookManagerInterface $book_manager * Book Manager Service. */ - public function __construct(BookManager $book_manager) { + public function __construct(BookManagerInterface $book_manager) { $this->bookManager = $book_manager; } diff --git a/core/modules/book/lib/Drupal/book/BookManager.php b/core/modules/book/lib/Drupal/book/BookManager.php index f184121..bc246f5 100644 --- a/core/modules/book/lib/Drupal/book/BookManager.php +++ b/core/modules/book/lib/Drupal/book/BookManager.php @@ -18,10 +18,7 @@ use Drupal\Core\Config\ConfigFactory; use Drupal\node\NodeInterface; -/** - * Book Manager Service. - */ -class BookManager { +class BookManager implements BookManagerInterface { /** * Defines the maximum supported depth of the book tree. @@ -74,13 +71,7 @@ public function __construct(Connection $connection, EntityManagerInterface $enti } /** - * 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. - * - * @return - * An array of all books. + * {@inheritdoc} */ public function getAllBooks() { if (!isset($this->books)) { @@ -121,13 +112,7 @@ protected function loadBooks() { } /** - * Returns an array with default values for a book page's menu link. - * - * @param string|int $nid - * The ID of the node whose menu link is being created. - * - * @return array - * The default values for the menu link. + * {@inheritdoc} */ public function getLinkDefaults($nid) { return array( @@ -142,13 +127,7 @@ public function getLinkDefaults($nid) { } /** - * Finds the depth limit for items in the parent select. - * - * @param array $book_link - * A fully loaded menu link that is part of the book hierarchy. - * - * @return int - * The depth limit for items in the parent select. + * {@inheritdoc} */ public function getParentDepthLimit(array $book_link) { return static::BOOK_MAX_DEPTH - 1 - (($book_link['bid'] && $book_link['has_children']) ? $this->findChildrenRelativeDepth($book_link) : 0); @@ -177,21 +156,7 @@ protected function findChildrenRelativeDepth(array $entity) { } /** - * Builds the common elements of the book form for the node and outline forms. - * - * @param array $form - * An associative array containing the structure of the form. - * @param array $form_state - * An associative array containing the current state of the form. - * @param \Drupal\node\NodeInterface $node - * The node whose form is being viewed. - * @param \Drupal\Core\Session\AccountInterface $account - * The account viewing the form. - * @param bool $collapsed - * If TRUE, the fieldset start out collpased.. - * - * @return array - * The form structure, with the book elements added. + * {@inheritdoc} */ public function addFormElements(array $form, array &$form_state, NodeInterface $node, AccountInterface $account, $collapsed = TRUE) { // If the form is being processed during the Ajax callback of our book bid @@ -274,33 +239,14 @@ public function addFormElements(array $form, array &$form_state, NodeInterface $ } /** - * Determines if a node can be removed from the book. - * - * A node can be removed from a book if it is actually in a book and it either - * is not a top-level page or is a top-level page with no children. - * - * @param \Drupal\node\NodeInterface $node - * The node to remove from the outline. - * - * @return bool - * TRUE if a node can be removed from the book, FALSE otherwise. + * {@inheritdoc} */ public function checkNodeIsRemovable(NodeInterface $node) { return (!empty($node->book['bid']) && (($node->book['bid'] != $node->id()) || !$node->book['has_children'])); } /** - * Handles additions and updates to the book outline. - * - * This common helper function performs all additions and updates to the book - * outline through node addition, node editing, node deletion, or the outline - * tab. - * - * @param \Drupal\node\NodeInterface $node - * The node that is being saved, added, deleted, or moved. - * - * @return bool - * TRUE if the book link was saved; FALSE otherwise. + * {@inheritdoc} */ public function updateOutline(NodeInterface $node) { if (empty($node->book['bid'])) { @@ -325,6 +271,9 @@ public function updateOutline(NodeInterface $node) { return $this->saveBookLink($node->book, $new); } + /** + * {@inheritdoc} + */ public function getBookParents(array $item, array $parent = array()) { $book = array(); if ($item['pid'] == 0) { @@ -363,10 +312,7 @@ protected function t($string, array $args = array(), array $options = array()) { } /** - * Updates the book ID of a page and its children when it moves to a new book. - * - * @param array $book_link - * A fully loaded menu link that is part of the book hierarchy. + * {@inheritdoc} */ public function updateId($book_link) { $query = $this->connection->select('book'); @@ -487,20 +433,7 @@ protected function recurseTableOfContents(array $tree, $indent, array &$toc, arr } /** - * Returns an array of book pages in table of contents order. - * - * @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). - * @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. - * - * @return array - * An array of (menu link ID, title) pairs for use as options for selecting a - * book page. + * {@inheritdoc} */ public function getTableOfContents($bid, $depth_limit, array $exclude = array()) { $tree = $this->bookTreeAllData($bid); @@ -511,10 +444,7 @@ public function getTableOfContents($bid, $depth_limit, array $exclude = array()) } /** - * Deletes node's entry from book table. - * - * @param int $nid - * The nid to delete. + * {@inheritdoc} */ public function deleteFromBook($nid) { $original = $this->loadBookLink($nid, FALSE); @@ -536,26 +466,7 @@ public function deleteFromBook($nid) { } /** - * Gets the data structure representing a named menu tree. - * - * Since this can be the full tree including hidden items, the data returned - * may be used for generating an an admin interface or a select. - * - * @param int $bid - * The Book ID to find links for. - * @param $link - * A fully loaded menu link, or NULL. If a link is supplied, only the - * path to root will be included in the returned tree - as if this link - * represented the current page in a visible menu. - * @param int $max_depth - * Optional maximum depth of links to retrieve. Typically useful if only one - * or two levels of a sub tree are needed in conjunction with a non-NULL - * $link, in which case $max_depth should be greater than $link['depth']. - * - * @return array - * An tree of menu links in an array, in the order they should be rendered. - * - * Note: copied from menu_tree_all_data(). + * {@inheritdoc} */ public function bookTreeAllData($bid, $link = NULL, $max_depth = NULL) { $tree = &drupal_static(__FUNCTION__, array()); @@ -607,21 +518,7 @@ public function bookTreeAllData($bid, $link = NULL, $max_depth = NULL) { } /** - * Returns a rendered menu tree. - * - * The menu item's LI element is given one of the following classes: - * - expanded: The menu item is showing its submenu. - * - collapsed: The menu item has a submenu which is not shown. - * - leaf: The menu item has no submenu. - * - * @param array $tree - * A data structure representing the tree as returned from menu_tree_data. - * - * @return array - * A structured array to be rendered by drupal_render(). - * - * Note: copied from menu_tree_output() but some hacky code using - * menu_get_item() was removed. + * {@inheritdoc} */ public function bookTreeOutput(array $tree) { $build = array(); @@ -791,12 +688,7 @@ protected function _menu_build_tree($bid, array $parameters = array()) { } /** - * Collects node links from a given menu tree recursively. - * - * @param array $tree - * The menu tree you wish to collect node links from. - * @param array $node_links - * An array in which to store the collected node links. + * {@inheritdoc} */ public function bookTreeCollectNodeLinks(&$tree, &$node_links) { // All book links are nodes. @@ -814,15 +706,7 @@ public function bookTreeCollectNodeLinks(&$tree, &$node_links) { } /** - * Load a single book entry. - * - * @param int $nid - * The node ID of the book. - * @param book $translate - * If TRUE, set access, title, and other elements. - * - * @return array - * The book data of that node. + * {@inheritdoc} */ public function loadBookLink($nid, $translate = TRUE) { $link = $this->connection->query("SELECT * FROM {book} WHERE nid = :nid", array(':nid' => $nid))->fetchAssoc(); @@ -833,13 +717,7 @@ public function loadBookLink($nid, $translate = TRUE) { } /** - * Save a single book entry. - * - * @param array $link - * The link data to save. - * - * @return array - * The book data of that node. + * {@inheritdoc} */ public function saveBookLink(array $link, $new) { if ($new) { @@ -928,10 +806,16 @@ protected function moveChildren(array $link, array $original) { } /** - * @todo: what happens here? + * Updates the has_children flag of the parent of the original book. + * + * This method is mostly called when a book is moved/created etc. so we want + * to update the has_children flag of the parent book. * * @param array $original - * @return type + * The book which parent we want to update. + * + * @return bool + * TRUE if there was no parent, otherwise TRUE on success, FALSE on failure. */ protected function updateParentalStatus(array $original) { if ($original['pid'] == 0) { @@ -978,13 +862,7 @@ protected function setParents(array &$link, array $parent) { } /** - * Checks access and performs dynamic operations for each link in the tree. - * - * @param array $tree - * The menu tree you wish to operate on. - * @param array $node_links - * A collection of node link references generated from $tree by - * menu_tree_collect_node_links(). + * {@inheritdoc} */ public function bookTreeCheckAccess(&$tree, $node_links = array()) { if ($node_links) { @@ -1031,16 +909,7 @@ protected function _menu_tree_check_access(&$tree) { } /** - * Provides menu link access control, translation, and argument handling. - * - * This function is similar to _menu_translate(), but it also does - * link-specific preparation (such as always calling to_arg() functions). - * - * @param array $link - * A book link. - * - * Note: copied from _menu_link_translate() in menu.inc, but reduced to the - * minimal code that's used. + * {@inheritdoc} */ public function bookLinkTranslate(&$link) { $node = NULL; @@ -1120,7 +989,7 @@ protected function _menu_tree_data(&$links, $parents, $depth) { // Fetch next link after filling the sub-tree. $next = end($links); } - // Determine if we should exit the loop and return. + // Determine if we should exit the loop and $request = return. if (!$next || $next['depth'] < $depth) { break; } @@ -1129,17 +998,7 @@ protected function _menu_tree_data(&$links, $parents, $depth) { } /** - * Gets the data representing a subtree of the book hierarchy. - * - * The root of the subtree will be the link passed as a parameter, so the - * returned tree will contain this item and all its descendents in the menu - * tree. - * - * @param $link - * A fully loaded menu link. - * - * @return - * A subtree of menu links in an array, in the order they should be rendered. + * {@inheritdoc} */ public function bookMenuSubtreeData($link) { $tree = &drupal_static(__FUNCTION__, array()); diff --git a/core/modules/book/lib/Drupal/book/BookManagerInterface.php b/core/modules/book/lib/Drupal/book/BookManagerInterface.php index c32190e..76e24ae 100644 --- a/core/modules/book/lib/Drupal/book/BookManagerInterface.php +++ b/core/modules/book/lib/Drupal/book/BookManagerInterface.php @@ -15,6 +15,7 @@ * Book Manager Service. */ interface BookManagerInterface { + /** * Gets the data structure representing a named menu tree. * @@ -44,7 +45,7 @@ public function bookTreeAllData($bid, $link = NULL, $max_depth = NULL); * * @param int $nid * The node ID of the book. - * @param book $translate + * @param bool $translate * If TRUE, set access, title, and other elements. * * @return array @@ -136,6 +137,8 @@ public function updateOutline(NodeInterface $node); * * @param array $link * The link data to save. + * @param bool $new + * Is this a new book. * * @return array * The book data of that node. diff --git a/core/modules/book/lib/Drupal/book/Controller/BookController.php b/core/modules/book/lib/Drupal/book/Controller/BookController.php index bf6277e..4067a74 100644 --- a/core/modules/book/lib/Drupal/book/Controller/BookController.php +++ b/core/modules/book/lib/Drupal/book/Controller/BookController.php @@ -9,6 +9,7 @@ use Drupal\book\BookManager; use Drupal\book\BookExport; +use Drupal\book\BookManagerInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\node\NodeInterface; use Symfony\Component\DependencyInjection\Container; @@ -24,7 +25,7 @@ class BookController implements ContainerInjectionInterface { /** * The book manager. * - * @var \Drupal\book\BookManager + * @var BookManagerInterface */ protected $bookManager; @@ -38,12 +39,12 @@ class BookController implements ContainerInjectionInterface { /** * Constructs a BookController object. * - * @param \Drupal\book\BookManager $bookManager + * @param BookManagerInterface $bookManager * The book manager. * @param \Drupal\book\BookExport $bookExport * The book export service. */ - public function __construct(BookManager $bookManager, BookExport $bookExport) { + public function __construct(BookManagerInterface $bookManager, BookExport $bookExport) { $this->bookManager = $bookManager; $this->bookExport = $bookExport; } diff --git a/core/modules/book/lib/Drupal/book/Form/BookAdminEditForm.php b/core/modules/book/lib/Drupal/book/Form/BookAdminEditForm.php index de57b07..d1db3c9 100644 --- a/core/modules/book/lib/Drupal/book/Form/BookAdminEditForm.php +++ b/core/modules/book/lib/Drupal/book/Form/BookAdminEditForm.php @@ -8,6 +8,7 @@ namespace Drupal\book\Form; use \Drupal\book\BookManager; +use Drupal\book\BookManagerInterface; use Drupal\Component\Utility\Crypt; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Entity\EntityStorageControllerInterface; @@ -38,7 +39,7 @@ class BookAdminEditForm extends FormBase { /** * The book manager. * - * @var \Drupal\book\BookManager + * @var BookManagerInterface */ protected $bookManager; @@ -49,10 +50,10 @@ class BookAdminEditForm extends FormBase { * The menu cache object to be used by this controller. * @param \Drupal\Core\Entity\EntityStorageControllerInterface $node_storage * The custom block storage controller. - * @param \Drupal\book\BookManager $book_manager + * @param BookManagerInterface $book_manager * The book manager. */ - public function __construct(CacheBackendInterface $cache, EntityStorageControllerInterface $node_storage, BookManager $book_manager) { + public function __construct(CacheBackendInterface $cache, EntityStorageControllerInterface $node_storage, BookManagerInterface $book_manager) { $this->cache = $cache; $this->nodeStorage = $node_storage; $this->bookManager = $book_manager; diff --git a/core/modules/book/lib/Drupal/book/Form/BookOutlineForm.php b/core/modules/book/lib/Drupal/book/Form/BookOutlineForm.php index 28aa7eb..78a5d28 100644 --- a/core/modules/book/lib/Drupal/book/Form/BookOutlineForm.php +++ b/core/modules/book/lib/Drupal/book/Form/BookOutlineForm.php @@ -7,6 +7,7 @@ namespace Drupal\book\Form; +use Drupal\book\BookManagerInterface; use Drupal\Core\Entity\ContentEntityFormController; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\book\BookManager; @@ -27,7 +28,7 @@ class BookOutlineForm extends ContentEntityFormController { /** * BookManager service. * - * @var \Drupal\book\BookManager + * @var BookManagerInterface */ protected $bookManager; @@ -36,10 +37,10 @@ class BookOutlineForm extends ContentEntityFormController { * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. - * @param \Drupal\book\BookManager $book_manager + * @param BookManagerInterface $book_manager * The BookManager service. */ - public function __construct(EntityManagerInterface $entity_manager, BookManager $book_manager) { + public function __construct(EntityManagerInterface $entity_manager, BookManagerInterface $book_manager) { parent::__construct($entity_manager); $this->bookManager = $book_manager; } diff --git a/core/modules/book/lib/Drupal/book/Form/BookRemoveForm.php b/core/modules/book/lib/Drupal/book/Form/BookRemoveForm.php index 2038d83..d370d7e 100644 --- a/core/modules/book/lib/Drupal/book/Form/BookRemoveForm.php +++ b/core/modules/book/lib/Drupal/book/Form/BookRemoveForm.php @@ -8,6 +8,7 @@ namespace Drupal\book\Form; use Drupal\book\BookManager; +use Drupal\book\BookManagerInterface; use Drupal\Core\Form\ConfirmFormBase; use Drupal\node\NodeInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -20,7 +21,7 @@ class BookRemoveForm extends ConfirmFormBase { /** * The book manager. * - * @var \Drupal\book\BookManager + * @var BookManagerInterface */ protected $bookManager; @@ -34,10 +35,10 @@ class BookRemoveForm extends ConfirmFormBase { /** * Constructs a BookRemoveForm object. * - * @param \Drupal\book\BookManager $book_manager + * @param BookManagerInterface $book_manager * The book manager. */ - public function __construct(BookManager $book_manager) { + public function __construct(BookManagerInterface $book_manager) { $this->bookManager = $book_manager; }