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