BookManagerInterface.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. namespace Drupal\book;
  3. use Drupal\Core\Form\FormStateInterface;
  4. use Drupal\Core\Session\AccountInterface;
  5. use Drupal\node\NodeInterface;
  6. /**
  7. * Provides an interface defining a book manager.
  8. */
  9. interface BookManagerInterface {
  10. /**
  11. * Gets the data structure representing a named menu tree.
  12. *
  13. * Since this can be the full tree including hidden items, the data returned
  14. * may be used for generating an an admin interface or a select.
  15. *
  16. * Note: based on menu_tree_all_data().
  17. *
  18. * @param int $bid
  19. * The Book ID to find links for.
  20. * @param array|null $link
  21. * (optional) A fully loaded menu link, or NULL. If a link is supplied, only
  22. * the path to root will be included in the returned tree - as if this link
  23. * represented the current page in a visible menu.
  24. * @param int|null $max_depth
  25. * (optional) Maximum depth of links to retrieve. Typically useful if only
  26. * one or two levels of a sub tree are needed in conjunction with a non-NULL
  27. * $link, in which case $max_depth should be greater than $link['depth'].
  28. *
  29. * @return array
  30. * An tree of menu links in an array, in the order they should be rendered.
  31. */
  32. public function bookTreeAllData($bid, $link = NULL, $max_depth = NULL);
  33. /**
  34. * Gets the active trail IDs for the specified book at the provided path.
  35. *
  36. * @param string $bid
  37. * The Book ID to find links for.
  38. * @param array $link
  39. * A fully loaded menu link.
  40. *
  41. * @return array
  42. * An array containing the active trail: a list of mlids.
  43. */
  44. public function getActiveTrailIds($bid, $link);
  45. /**
  46. * Loads a single book entry.
  47. *
  48. * The entries of a book entry is documented in
  49. * \Drupal\book\BookOutlineStorageInterface::loadMultiple.
  50. *
  51. * If $translate is TRUE, it also checks access ('access' key) and
  52. * loads the title from the node itself.
  53. *
  54. * @param int $nid
  55. * The node ID of the book.
  56. * @param bool $translate
  57. * If TRUE, set access, title, and other elements.
  58. *
  59. * @return array
  60. * The book data of that node.
  61. *
  62. * @see \Drupal\book\BookOutlineStorageInterface::loadMultiple
  63. */
  64. public function loadBookLink($nid, $translate = TRUE);
  65. /**
  66. * Loads multiple book entries.
  67. *
  68. * The entries of a book entry is documented in
  69. * \Drupal\book\BookOutlineStorageInterface::loadMultiple.
  70. *
  71. * If $translate is TRUE, it also checks access ('access' key) and
  72. * loads the title from the node itself.
  73. *
  74. * @param int[] $nids
  75. * An array of nids to load.
  76. * @param bool $translate
  77. * If TRUE, set access, title, and other elements.
  78. *
  79. * @return array[]
  80. * The book data of each node keyed by NID.
  81. *
  82. * @see \Drupal\book\BookOutlineStorageInterface::loadMultiple
  83. */
  84. public function loadBookLinks($nids, $translate = TRUE);
  85. /**
  86. * Returns an array of book pages in table of contents order.
  87. *
  88. * @param int $bid
  89. * The ID of the book whose pages are to be listed.
  90. * @param int $depth_limit
  91. * Any link deeper than this value will be excluded (along with its
  92. * children).
  93. * @param array $exclude
  94. * (optional) An array of menu link ID values. Any link whose menu link ID
  95. * is in this array will be excluded (along with its children). Defaults to
  96. * an empty array.
  97. *
  98. * @return array
  99. * An array of (menu link ID, title) pairs for use as options for selecting
  100. * a book page.
  101. */
  102. public function getTableOfContents($bid, $depth_limit, array $exclude = []);
  103. /**
  104. * Finds the depth limit for items in the parent select.
  105. *
  106. * @param array $book_link
  107. * A fully loaded menu link that is part of the book hierarchy.
  108. *
  109. * @return int
  110. * The depth limit for items in the parent select.
  111. */
  112. public function getParentDepthLimit(array $book_link);
  113. /**
  114. * Collects node links from a given menu tree recursively.
  115. *
  116. * @param array $tree
  117. * The menu tree you wish to collect node links from.
  118. * @param array $node_links
  119. * An array in which to store the collected node links.
  120. */
  121. public function bookTreeCollectNodeLinks(&$tree, &$node_links);
  122. /**
  123. * Provides book loading, access control and translation.
  124. *
  125. * Note: copied from _menu_link_translate() in menu.inc, but reduced to the
  126. * minimal code that's used.
  127. *
  128. * @param array $link
  129. * A book link.
  130. */
  131. public function bookLinkTranslate(&$link);
  132. /**
  133. * Gets the book for a page and returns it as a linear array.
  134. *
  135. * @param array $book_link
  136. * A fully loaded book link that is part of the book hierarchy.
  137. *
  138. * @return array
  139. * A linear array of book links in the order that the links are shown in the
  140. * book, so the previous and next pages are the elements before and after the
  141. * element corresponding to the current node. The children of the current node
  142. * (if any) will come immediately after it in the array, and links will only
  143. * be fetched as deep as one level deeper than $book_link.
  144. */
  145. public function bookTreeGetFlat(array $book_link);
  146. /**
  147. * Returns an array of all books.
  148. *
  149. * This list may be used for generating a list of all the books, or for
  150. * building the options for a form select.
  151. *
  152. * @return array
  153. * An array of all books.
  154. */
  155. public function getAllBooks();
  156. /**
  157. * Handles additions and updates to the book outline.
  158. *
  159. * This common helper function performs all additions and updates to the book
  160. * outline through node addition, node editing, node deletion, or the outline
  161. * tab.
  162. *
  163. * @param \Drupal\node\NodeInterface $node
  164. * The node that is being saved, added, deleted, or moved.
  165. *
  166. * @return bool
  167. * TRUE if the book link was saved; FALSE otherwise.
  168. */
  169. public function updateOutline(NodeInterface $node);
  170. /**
  171. * Saves a single book entry.
  172. *
  173. * @param array $link
  174. * The link data to save.
  175. * @param bool $new
  176. * Is this a new book.
  177. *
  178. * @return array
  179. * The book data of that node.
  180. */
  181. public function saveBookLink(array $link, $new);
  182. /**
  183. * Returns an array with default values for a book page's menu link.
  184. *
  185. * @param string|int $nid
  186. * The ID of the node whose menu link is being created.
  187. *
  188. * @return array
  189. * The default values for the menu link.
  190. */
  191. public function getLinkDefaults($nid);
  192. public function getBookParents(array $item, array $parent = []);
  193. /**
  194. * Builds the common elements of the book form for the node and outline forms.
  195. *
  196. * @param array $form
  197. * An associative array containing the structure of the form.
  198. * @param \Drupal\Core\Form\FormStateInterface $form_state
  199. * The current state of the form.
  200. * @param \Drupal\node\NodeInterface $node
  201. * The node whose form is being viewed.
  202. * @param \Drupal\Core\Session\AccountInterface $account
  203. * The account viewing the form.
  204. * @param bool $collapsed
  205. * If TRUE, the fieldset starts out collapsed.
  206. *
  207. * @return array
  208. * The form structure, with the book elements added.
  209. */
  210. public function addFormElements(array $form, FormStateInterface $form_state, NodeInterface $node, AccountInterface $account, $collapsed = TRUE);
  211. /**
  212. * Deletes node's entry from book table.
  213. *
  214. * @param int $nid
  215. * The nid to delete.
  216. */
  217. public function deleteFromBook($nid);
  218. /**
  219. * Returns a rendered menu tree.
  220. *
  221. * The menu item's LI element is given one of the following classes:
  222. * - expanded: The menu item is showing its submenu.
  223. * - collapsed: The menu item has a submenu which is not shown.
  224. *
  225. * @param array $tree
  226. * A data structure representing the tree as returned from buildBookOutlineData.
  227. *
  228. * @return array
  229. * A structured array to be rendered by
  230. * \Drupal\Core\Render\RendererInterface::render().
  231. *
  232. * @see \Drupal\Core\Menu\MenuLinkTree::build
  233. */
  234. public function bookTreeOutput(array $tree);
  235. /**
  236. * Checks access and performs dynamic operations for each link in the tree.
  237. *
  238. * @param array $tree
  239. * The book tree you wish to operate on.
  240. * @param array $node_links
  241. * A collection of node link references generated from $tree by
  242. * menu_tree_collect_node_links().
  243. */
  244. public function bookTreeCheckAccess(&$tree, $node_links = []);
  245. /**
  246. * Gets the data representing a subtree of the book hierarchy.
  247. *
  248. * The root of the subtree will be the link passed as a parameter, so the
  249. * returned tree will contain this item and all its descendants in the menu
  250. * tree.
  251. *
  252. * @param array $link
  253. * A fully loaded book link.
  254. *
  255. * @return
  256. * A subtree of book links in an array, in the order they should be rendered.
  257. */
  258. public function bookSubtreeData($link);
  259. /**
  260. * Determines if a node can be removed from the book.
  261. *
  262. * A node can be removed from a book if it is actually in a book and it either
  263. * is not a top-level page or is a top-level page with no children.
  264. *
  265. * @param \Drupal\node\NodeInterface $node
  266. * The node to remove from the outline.
  267. *
  268. * @return bool
  269. * TRUE if a node can be removed from the book, FALSE otherwise.
  270. */
  271. public function checkNodeIsRemovable(NodeInterface $node);
  272. }