interface BookManagerInterface (View source)

Provides an interface defining a book manager.

Methods

array
bookTreeAllData(int $bid, array|null $link = NULL, int|null $max_depth = NULL)

Gets the data structure representing a named menu tree.

array
getActiveTrailIds(string $bid, array $link)

Gets the active trail IDs for the specified book at the provided path.

array
loadBookLink(int $nid, bool $translate = TRUE)

Loads a single book entry.

array[]
loadBookLinks(int[] $nids, bool $translate = TRUE)

Loads multiple book entries.

array
getTableOfContents(int $bid, int $depth_limit, array $exclude = [])

Returns an array of book pages in table of contents order.

int
getParentDepthLimit(array $book_link)

Finds the depth limit for items in the parent select.

bookTreeCollectNodeLinks(array $tree, array $node_links)

Collects node links from a given menu tree recursively.

bookLinkTranslate(array $link)

Provides book loading, access control and translation.

array
bookTreeGetFlat(array $book_link)

Gets the book for a page and returns it as a linear array.

array
getAllBooks()

Returns an array of all books.

bool
updateOutline(NodeInterface $node)

Handles additions and updates to the book outline.

array
saveBookLink(array $link, bool $new)

Saves a single book entry.

array
getLinkDefaults(string|int $nid)

Returns an array with default values for a book page's menu link.

getBookParents(array $item, array $parent = [])

No description

array
addFormElements(array $form, FormStateInterface $form_state, NodeInterface $node, AccountInterface $account, bool $collapsed = TRUE)

Builds the common elements of the book form for the node and outline forms.

deleteFromBook(int $nid)

Deletes node's entry from book table.

array
bookTreeOutput(array $tree)

Returns a rendered menu tree.

bookTreeCheckAccess(array $tree, array $node_links = [])

Checks access and performs dynamic operations for each link in the tree.

A
bookSubtreeData(array $link)

Gets the data representing a subtree of the book hierarchy.

bool
checkNodeIsRemovable(NodeInterface $node)

Determines if a node can be removed from the book.

Details

array bookTreeAllData(int $bid, array|null $link = NULL, int|null $max_depth = NULL)

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 admin interface or a select.

Note: based on menu_tree_all_data().

Parameters

int $bid

The Book ID to find links for.

array|null $link

(optional) 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.

int|null $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 Value

array

An tree of menu links in an array, in the order they should be rendered.

array getActiveTrailIds(string $bid, array $link)

Gets the active trail IDs for the specified book at the provided path.

Parameters

string $bid

The Book ID to find links for.

array $link

A fully loaded menu link.

Return Value

array

An array containing the active trail: a list of mlids.

Loads a single book entry.

The entries of a book entry is documented in \Drupal\book\BookOutlineStorageInterface::loadMultiple.

If $translate is TRUE, it also checks access ('access' key) and loads the title from the node itself.

Parameters

int $nid

The node ID of the book.

bool $translate

If TRUE, set access, title, and other elements.

Return Value

array

The book data of that node.

See also

BookOutlineStorageInterface::loadMultiple

Loads multiple book entries.

The entries of a book entry is documented in \Drupal\book\BookOutlineStorageInterface::loadMultiple.

If $translate is TRUE, it also checks access ('access' key) and loads the title from the node itself.

Parameters

int[] $nids

An array of nids to load.

bool $translate

If TRUE, set access, title, and other elements.

Return Value

array[]

The book data of each node keyed by NID.

See also

BookOutlineStorageInterface::loadMultiple

array getTableOfContents(int $bid, int $depth_limit, array $exclude = [])

Returns an array of book pages in table of contents order.

Parameters

int $bid

The ID of the book whose pages are to be listed.

int $depth_limit

Any link deeper than this value will be excluded (along with its children).

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 Value

array

An array of (menu link ID, title) pairs for use as options for selecting a book page.

int getParentDepthLimit(array $book_link)

Finds the depth limit for items in the parent select.

Parameters

array $book_link

A fully loaded menu link that is part of the book hierarchy.

Return Value

int

The depth limit for items in the parent select.

Collects node links from a given menu tree recursively.

Parameters

array $tree

The menu tree you wish to collect node links from.

array $node_links

An array in which to store the collected node links.

bookLinkTranslate(array $link)

Provides book loading, access control and translation.

Note: copied from _menu_link_translate() in menu.inc, but reduced to the minimal code that's used.

Parameters

array $link

A book link.

array bookTreeGetFlat(array $book_link)

Gets the book for a page and returns it as a linear array.

Parameters

array $book_link

A fully loaded book link that is part of the book hierarchy.

Return Value

array

A linear array of book links in the order that the links are shown in the book, 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 (if any) will come immediately after it in the array, and links will only be fetched as deep as one level deeper than $book_link.

array getAllBooks()

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 Value

array

An array of all books.

bool updateOutline(NodeInterface $node)

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.

Parameters

NodeInterface $node

The node that is being saved, added, deleted, or moved.

Return Value

bool

TRUE if the book link was saved; FALSE otherwise.

Saves a single book entry.

Parameters

array $link

The link data to save.

bool $new

Is this a new book.

Return Value

array

The book data of that node.

array getLinkDefaults(string|int $nid)

Returns an array with default values for a book page's menu link.

Parameters

string|int $nid

The ID of the node whose menu link is being created.

Return Value

array

The default values for the menu link.

getBookParents(array $item, array $parent = [])

No description

Parameters

array $item
array $parent

array addFormElements(array $form, FormStateInterface $form_state, NodeInterface $node, AccountInterface $account, bool $collapsed = TRUE)

Builds the common elements of the book form for the node and outline forms.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

NodeInterface $node

The node whose form is being viewed.

AccountInterface $account

The account viewing the form.

bool $collapsed

If TRUE, the fieldset starts out collapsed.

Return Value

array

The form structure, with the book elements added.

deleteFromBook(int $nid)

Deletes node's entry from book table.

Parameters

int $nid

The nid to delete.

array bookTreeOutput(array $tree)

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.

Parameters

array $tree

A data structure representing the tree as returned from buildBookOutlineData.

Return Value

array

A structured array to be rendered by \Drupal\Core\Render\RendererInterface::render().

See also

MenuLinkTree::build

bookTreeCheckAccess(array $tree, array $node_links = [])

Checks access and performs dynamic operations for each link in the tree.

Parameters

array $tree

The book tree you wish to operate on.

array $node_links

A collection of node link references generated from $tree by menu_tree_collect_node_links().

A bookSubtreeData(array $link)

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 descendants in the menu tree.

Parameters

array $link

A fully loaded book link.

Return Value

A

subtree of book links in an array, in the order they should be rendered.

bool checkNodeIsRemovable(NodeInterface $node)

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.

Parameters

NodeInterface $node

The node to remove from the outline.

Return Value

bool

TRUE if a node can be removed from the book, FALSE otherwise.