BookManager
class BookManager implements BookManagerInterface (View source)
Defines a book manager.
Traits
Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.
Constants
| BOOK_MAX_DEPTH |
Defines the maximum supported depth of the book tree. |
Properties
| protected TranslationInterface | $stringTranslation | The string translation service. |
from StringTranslationTrait |
| protected EntityTypeManagerInterface | $entityTypeManager | Entity type manager. |
|
| protected ConfigFactoryInterface | $configFactory | Config Factory Service Object. |
|
| protected array | $books | Books Array. |
|
| protected BookOutlineStorageInterface | $bookOutlineStorage | Book outline storage. |
|
| protected array | $bookTreeFlattened | Stores flattened book trees. |
|
| protected RendererInterface | $renderer | The renderer. |
|
| protected EntityRepositoryInterface | $entityRepository | The entity repository service. |
|
| protected LanguageManagerInterface|mixed|null | $languageManager | The language manager. |
|
| protected CacheBackendInterface | $backendChainedCache | The book chained backend cache service. |
|
| protected CacheBackendInterface | $memoryCache | The book memory cache service. |
Methods
Translates a string to the current language or to a given language.
Formats a string containing a count of items.
Returns the number of plurals supported by a given language.
Gets the string translation service.
Constructs a BookManager object.
Returns an array of all books.
Loads Books Array.
Returns an array with default values for a book page's menu link.
Finds the depth limit for items in the parent select.
Determine the relative depth of the children of a given book link.
Builds the common elements of the book form for the node and outline forms.
No description
Builds the parent selection form element for the node form or outline tab.
Recursively processes and formats book links for getTableOfContents().
Returns an array of book pages in table of contents order.
Deletes node's entry from book table.
Gets the data structure representing a named menu tree.
Gets the active trail IDs for the specified book at the provided path.
Returns a rendered menu tree.
Builds the #items property for a book tree's renderable array.
Builds a book tree, translates links, and checks access.
Builds a book tree.
Collects node links from a given menu tree recursively.
Gets the book for a page and returns it as a linear array.
Recursively converts a tree of menu links to a flat array.
Loads a single book entry.
Loads multiple book entries.
Saves a single book entry.
Moves children from the original parent to the updated link.
Sets the has_children flag of the parent of the node.
Updates the has_children flag of the parent of the original node.
Sets the p1 through p9 properties for a book link being saved.
Checks access and performs dynamic operations for each link in the tree.
Sorts the menu tree and recursively checks access for each item.
Provides book loading, access control and translation.
Sorts and returns the built data representing a book tree.
Builds the data representing a book tree.
Gets the data representing a subtree of the book hierarchy.
Details
protected TranslatableMarkup
t(string $string, array $args = [], array $options = [])
Translates a string to the current language or to a given language.
See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.
In order for strings to be localized, make them available in one of the ways supported by the
protected
formatPlural($count, $singular, $plural, array $args = [], array $options = [])
Formats a string containing a count of items.
protected
getNumberOfPlurals($langcode = NULL)
Returns the number of plurals supported by a given language.
protected TranslationInterface
getStringTranslation()
Gets the string translation service.
$this
setStringTranslation(TranslationInterface $translation)
Sets the string translation service to use.
__construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $translation, ConfigFactoryInterface $config_factory, BookOutlineStorageInterface $book_outline_storage, RendererInterface $renderer, LanguageManagerInterface $language_manager = NULL, EntityRepositoryInterface $entity_repository = NULL, CacheBackendInterface $backend_chained_cache = NULL, CacheBackendInterface $memory_cache = NULL)
Constructs a BookManager object.
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.
protected
loadBooks()
Loads Books Array.
array
getLinkDefaults(string|int $nid)
Returns an array with default values for a book page's menu link.
int
getParentDepthLimit(array $book_link)
Finds the depth limit for items in the parent select.
protected int
findChildrenRelativeDepth(array $book_link)
Determine the relative depth of the children of a given book link.
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.
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.
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.
getBookParents(array $item, array $parent = [])
No description
protected array
addParentSelectFormElements(array $book_link)
Builds the parent selection form element for the node form or outline tab.
This function is also called when generating a new set of options during the Ajax callback, so an array is returned that can be used to replace an existing form element.
protected
recurseTableOfContents(array $tree, string $indent, array $toc, array $exclude, int $depth_limit)
Recursively processes and formats book links for getTableOfContents().
This helper function recursively modifies the table of contents array for each item in the book tree, ignoring items in the exclude array or at a depth greater than the limit. Truncates titles over thirty characters and appends an indentation string incremented by depth.
array
getTableOfContents(int $bid, int $depth_limit, array $exclude = [])
Returns an array of book pages in table of contents order.
deleteFromBook(int $nid)
Deletes node's entry from book table.
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().
array
getActiveTrailIds(string $bid, array $link)
Gets the active trail IDs for the specified book at the provided path.
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.
protected array
buildItems(array $tree)
Builds the #items property for a book tree's renderable array.
Helper function for ::bookTreeOutput().
protected array
bookTreeBuild(int $bid, array $parameters = [])
Builds a book tree, translates links, and checks access.
protected array
doBookTreeBuild(int $bid, array $parameters = [])
Builds a book tree.
This function may be used build the data for a menu tree only, for example to further massage the data manually before further processing happens. _menu_tree_check_access() needs to be invoked afterwards.
bookTreeCollectNodeLinks(array $tree, array $node_links)
Collects node links from a given menu tree recursively.
array
bookTreeGetFlat(array $book_link)
Gets the book for a page and returns it as a linear array.
protected
flatBookTree(array $tree, array $flat)
Recursively converts a tree of menu links to a flat array.
array
loadBookLink(int $nid, bool $translate = TRUE)
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.
array[]
loadBookLinks(int[] $nids, bool $translate = TRUE)
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.
array
saveBookLink(array $link, bool $new)
Saves a single book entry.
protected
moveChildren(array $link, array $original)
Moves children from the original parent to the updated link.
protected bool
updateParent(array $link)
Sets the has_children flag of the parent of the node.
This method is mostly called when a book link is moved/created etc. So we want to update the has_children flag of the new parent book link.
protected bool
updateOriginalParent(array $original)
Updates the has_children flag of the parent of the original node.
This method is called when a book link is moved or deleted. So we want to update the has_children flag of the parent node.
protected
setParents(array $link, array $parent)
Sets the p1 through p9 properties for a book link being saved.
bookTreeCheckAccess(array $tree, array $node_links = [])
Checks access and performs dynamic operations for each link in the tree.
protected
doBookTreeCheckAccess(array $tree)
Sorts the menu tree and recursively checks access for each item.
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.
protected array
buildBookOutlineData(array $links, array $parents = [], int $depth = 1)
Sorts and returns the built data representing a book tree.
protected array
buildBookOutlineRecursive(array $links, array $parents, int $depth)
Builds the data representing a book tree.
The function is a bit complex because the rendering of a link depends on the next book link.
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.