bookTreeAllData example


  public function testMultilingualBookManager(string $langcode) {
    $this->setCurrentLanguage($langcode);
    /** @var \Drupal\book\BookManagerInterface $bm */
    $bm = $this->container->get('book.manager');
    $books = $bm->getAllBooks();
    $this->assertNotEmpty($books);
    foreach ($books as $book) {
      $bid = $book['bid'];
      $build = $bm->bookTreeOutput($bm->bookTreeAllData($bid));
      $items = $build['#items'];
      $this->assertBookItemIsCorrectlyTranslated($items[$bid]$langcode);
      $this->assertBookItemIsCorrectlyTranslated($items[$bid]['below'][$bid + 1]$langcode);
      $this->assertBookItemIsCorrectlyTranslated($items[$bid]['below'][$bid + 1]['below'][$bid + 3]$langcode);
      $this->assertBookItemIsCorrectlyTranslated($items[$bid]['below'][$bid + 1]['below'][$bid + 4]$langcode);
      $this->assertBookItemIsCorrectlyTranslated($items[$bid]['below'][$bid + 2]$langcode);
      $this->assertBookItemIsCorrectlyTranslated($items[$bid]['below'][$bid + 2]['below'][$bid + 5]$langcode);
      $this->assertBookItemIsCorrectlyTranslated($items[$bid]['below'][$bid + 2]['below'][$bid + 6]$langcode);
      $toc = $bm->getTableOfContents($bid, 4);
      // Root entry does not have an indent.       $this->assertToCEntryIsCorrectlyTranslated($toc$langcode$bid, '');
      
$this->assertSame('6', $nodes[1]->book['pid']);

    $this->assertSame('4', $nodes[2]->book['bid']);
    $this->assertSame('6', $nodes[2]->book['pid']);

    $this->assertSame('4', $nodes[4]->book['bid']);
    $this->assertSame('0', $nodes[4]->book['pid']);

    $this->assertSame('4', $nodes[6]->book['bid']);
    $this->assertSame('4', $nodes[6]->book['pid']);

    $tree = \Drupal::service('book.manager')->bookTreeAllData(4);
    $this->assertSame('4', $tree['49990 is - The thing about Firefly 4']['link']['nid']);
    $this->assertSame('6', $tree['49990 is - The thing about Firefly 4']['below']['50000 Comments are closed :-( 6']['link']['nid']);
    $this->assertSame('2', $tree['49990 is - The thing about Firefly 4']['below']['50000 Comments are closed :-( 6']['below']['50000 The thing about Deep Space 9 2']['link']['nid']);
    $this->assertSame([]$tree['49990 is - The thing about Firefly 4']['below']['50000 Comments are closed :-( 6']['below']['50000 The thing about Deep Space 9 2']['below']);

    // Set the d7_book migration to update and re run the migration.     $id_map = $this->migration->getIdMap();
    $id_map->prepareUpdate();
    $this->executeMigration('d7_book');
  }

}
$this->assertSame('4', $nodes[5]->book['pid']);

    $this->assertSame('4', $nodes[6]->book['bid']);
    $this->assertSame('5', $nodes[6]->book['pid']);

    $this->assertSame('4', $nodes[7]->book['bid']);
    $this->assertSame('5', $nodes[7]->book['pid']);

    $this->assertSame('8', $nodes[8]->book['bid']);
    $this->assertSame('0', $nodes[8]->book['pid']);

    $tree = \Drupal::service('book.manager')->bookTreeAllData(4);
    $this->assertSame('4', $tree['49990 Node 4 4']['link']['nid']);
    $this->assertSame('5', $tree['49990 Node 4 4']['below']['50000 Node 5 5']['link']['nid']);
    $this->assertSame('6', $tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 6 6']['link']['nid']);
    $this->assertSame('7', $tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 7 7']['link']['nid']);
    $this->assertSame([]$tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 6 6']['below']);
    $this->assertSame([]$tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 7 7']['below']);

    // Set the d6_book migration to update and re run the migration.     $id_map = $this->migration->getIdMap();
    $id_map->prepareUpdate();
    $this->executeMigration('d6_book');
  }
$toc[$nid] = $indent . ' ' . Unicode::truncate($nodes[$nid]->label(), 30, TRUE, TRUE);
      if ($data['below']) {
        $this->recurseTableOfContents($data['below']$indent . '--', $toc$exclude$depth_limit);
      }
    }
  }

  /** * {@inheritdoc} */
  public function getTableOfContents($bid$depth_limit, array $exclude = []) {
    $tree = $this->bookTreeAllData($bid);
    $toc = [];
    $this->recurseTableOfContents($tree, '', $toc$exclude$depth_limit);

    return $toc;
  }

  /** * {@inheritdoc} */
  public function deleteFromBook($nid) {
    $original = $this->loadBookLink($nid, FALSE);
    
$node = $this->routeMatch->getParameter('node');
    if ($node instanceof NodeInterface && !empty($node->book['bid'])) {
      $current_bid = $node->book['bid'];
    }
    if ($this->configuration['block_mode'] == 'all pages') {
      $book_menus = [];
      $pseudo_tree = [0 => ['below' => FALSE]];
      foreach ($this->bookManager->getAllBooks() as $book_id => $book) {
        if ($book['bid'] == $current_bid) {
          // If the current page is a node associated with a book, the menu           // needs to be retrieved.           $data = $this->bookManager->bookTreeAllData($node->book['bid']$node->book);
          $book_menus[$book_id] = $this->bookManager->bookTreeOutput($data);
        }
        else {
          // Since we know we will only display a link to the top node, there           // is no reason to run an additional menu tree query for each book.           $book['in_active_trail'] = FALSE;
          // Check whether user can access the book link.           $book_node = $this->nodeStorage->load($book['nid']);
          $book['access'] = $book_node->access('view');
          $pseudo_tree[0]['link'] = $book;
          $book_menus[$book_id] = $this->bookManager->bookTreeOutput($pseudo_tree);
        }
Home | Imprint | This part of the site doesn't use cookies.