function template_preprocess_book_all_books_block

Same name in other branches
  1. 7.x modules/book/book.module \template_preprocess_book_all_books_block()
  2. 8.9.x core/modules/book/book.module \template_preprocess_book_all_books_block()
  3. 10 core/modules/book/book.module \template_preprocess_book_all_books_block()
  4. 11.x core/modules/book/book.module \template_preprocess_book_all_books_block()

Prepares variables for book listing block templates.

Default template: book-all-books-block.html.twig.

All non-renderable elements are removed so that the template has full access to the structured data but can also simply iterate over all elements and render them (as in the default template).

Parameters

array $variables: An associative array containing the following key:

  • book_menus: An associative array containing renderable menu links for all book menus.

File

core/modules/book/book.module, line 366

Code

function template_preprocess_book_all_books_block(&$variables) {
    // Remove all non-renderable elements.
    $elements = $variables['book_menus'];
    $variables['book_menus'] = [];
    foreach (Element::children($elements) as $index) {
        $variables['book_menus'][] = [
            'id' => $index,
            'menu' => $elements[$index],
            'title' => $elements[$index]['#book_title'],
        ];
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.