5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\Core\Session\AccountInterface;
7 use Drupal\node\NodeInterface;
10 * Provides an interface defining a book manager.
12 interface BookManagerInterface {
15 * Gets the data structure representing a named menu tree.
17 * Since this can be the full tree including hidden items, the data returned
18 * may be used for generating an an admin interface or a select.
20 * Note: based on menu_tree_all_data().
23 * The Book ID to find links for.
24 * @param array|null $link
25 * (optional) A fully loaded menu link, or NULL. If a link is supplied, only
26 * the path to root will be included in the returned tree - as if this link
27 * represented the current page in a visible menu.
28 * @param int|null $max_depth
29 * (optional) Maximum depth of links to retrieve. Typically useful if only
30 * one or two levels of a sub tree are needed in conjunction with a non-NULL
31 * $link, in which case $max_depth should be greater than $link['depth'].
34 * An tree of menu links in an array, in the order they should be rendered.
36 public function bookTreeAllData($bid, $link = NULL, $max_depth = NULL);
39 * Gets the active trail IDs for the specified book at the provided path.
42 * The Book ID to find links for.
44 * A fully loaded menu link.
47 * An array containing the active trail: a list of mlids.
49 public function getActiveTrailIds($bid, $link);
52 * Loads a single book entry.
54 * The entries of a book entry is documented in
55 * \Drupal\book\BookOutlineStorageInterface::loadMultiple.
57 * If $translate is TRUE, it also checks access ('access' key) and
58 * loads the title from the node itself.
61 * The node ID of the book.
62 * @param bool $translate
63 * If TRUE, set access, title, and other elements.
66 * The book data of that node.
68 * @see \Drupal\book\BookOutlineStorageInterface::loadMultiple
70 public function loadBookLink($nid, $translate = TRUE);
73 * Loads multiple book entries.
75 * The entries of a book entry is documented in
76 * \Drupal\book\BookOutlineStorageInterface::loadMultiple.
78 * If $translate is TRUE, it also checks access ('access' key) and
79 * loads the title from the node itself.
82 * An array of nids to load.
83 * @param bool $translate
84 * If TRUE, set access, title, and other elements.
87 * The book data of each node keyed by NID.
89 * @see \Drupal\book\BookOutlineStorageInterface::loadMultiple
91 public function loadBookLinks($nids, $translate = TRUE);
94 * Returns an array of book pages in table of contents order.
97 * The ID of the book whose pages are to be listed.
98 * @param int $depth_limit
99 * Any link deeper than this value will be excluded (along with its
101 * @param array $exclude
102 * (optional) An array of menu link ID values. Any link whose menu link ID
103 * is in this array will be excluded (along with its children). Defaults to
107 * An array of (menu link ID, title) pairs for use as options for selecting
110 public function getTableOfContents($bid, $depth_limit, array $exclude = []);
113 * Finds the depth limit for items in the parent select.
115 * @param array $book_link
116 * A fully loaded menu link that is part of the book hierarchy.
119 * The depth limit for items in the parent select.
121 public function getParentDepthLimit(array $book_link);
124 * Collects node links from a given menu tree recursively.
127 * The menu tree you wish to collect node links from.
128 * @param array $node_links
129 * An array in which to store the collected node links.
131 public function bookTreeCollectNodeLinks(&$tree, &$node_links);
134 * Provides book loading, access control and translation.
136 * Note: copied from _menu_link_translate() in menu.inc, but reduced to the
137 * minimal code that's used.
142 public function bookLinkTranslate(&$link);
145 * Gets the book for a page and returns it as a linear array.
147 * @param array $book_link
148 * A fully loaded book link that is part of the book hierarchy.
151 * A linear array of book links in the order that the links are shown in the
152 * book, so the previous and next pages are the elements before and after the
153 * element corresponding to the current node. The children of the current node
154 * (if any) will come immediately after it in the array, and links will only
155 * be fetched as deep as one level deeper than $book_link.
157 public function bookTreeGetFlat(array $book_link);
160 * Returns an array of all books.
162 * This list may be used for generating a list of all the books, or for
163 * building the options for a form select.
166 * An array of all books.
168 public function getAllBooks();
171 * Handles additions and updates to the book outline.
173 * This common helper function performs all additions and updates to the book
174 * outline through node addition, node editing, node deletion, or the outline
177 * @param \Drupal\node\NodeInterface $node
178 * The node that is being saved, added, deleted, or moved.
181 * TRUE if the book link was saved; FALSE otherwise.
183 public function updateOutline(NodeInterface $node);
186 * Saves a single book entry.
189 * The link data to save.
191 * Is this a new book.
194 * The book data of that node.
196 public function saveBookLink(array $link, $new);
199 * Returns an array with default values for a book page's menu link.
201 * @param string|int $nid
202 * The ID of the node whose menu link is being created.
205 * The default values for the menu link.
207 public function getLinkDefaults($nid);
209 public function getBookParents(array $item, array $parent = []);
212 * Builds the common elements of the book form for the node and outline forms.
215 * An associative array containing the structure of the form.
216 * @param \Drupal\Core\Form\FormStateInterface $form_state
217 * The current state of the form.
218 * @param \Drupal\node\NodeInterface $node
219 * The node whose form is being viewed.
220 * @param \Drupal\Core\Session\AccountInterface $account
221 * The account viewing the form.
222 * @param bool $collapsed
223 * If TRUE, the fieldset starts out collapsed.
226 * The form structure, with the book elements added.
228 public function addFormElements(array $form, FormStateInterface $form_state, NodeInterface $node, AccountInterface $account, $collapsed = TRUE);
231 * Deletes node's entry from book table.
236 public function deleteFromBook($nid);
239 * Returns a rendered menu tree.
241 * The menu item's LI element is given one of the following classes:
242 * - expanded: The menu item is showing its submenu.
243 * - collapsed: The menu item has a submenu which is not shown.
246 * A data structure representing the tree as returned from buildBookOutlineData.
249 * A structured array to be rendered by
250 * \Drupal\Core\Render\RendererInterface::render().
252 * @see \Drupal\Core\Menu\MenuLinkTree::build
254 public function bookTreeOutput(array $tree);
257 * Checks access and performs dynamic operations for each link in the tree.
260 * The book tree you wish to operate on.
261 * @param array $node_links
262 * A collection of node link references generated from $tree by
263 * menu_tree_collect_node_links().
265 public function bookTreeCheckAccess(&$tree, $node_links = []);
268 * Gets the data representing a subtree of the book hierarchy.
270 * The root of the subtree will be the link passed as a parameter, so the
271 * returned tree will contain this item and all its descendants in the menu
275 * A fully loaded book link.
278 * A subtree of book links in an array, in the order they should be rendered.
280 public function bookSubtreeData($link);
283 * Determines if a node can be removed from the book.
285 * A node can be removed from a book if it is actually in a book and it either
286 * is not a top-level page or is a top-level page with no children.
288 * @param \Drupal\node\NodeInterface $node
289 * The node to remove from the outline.
292 * TRUE if a node can be removed from the book, FALSE otherwise.
294 public function checkNodeIsRemovable(NodeInterface $node);