createBookNode example

/** * Creates a new book with a page hierarchy. * * @return \Drupal\node\NodeInterface[] * The created book nodes. */
  protected function createBreadcrumbBook() {
    // Create new book.     $this->drupalLogin($this->bookAuthor);

    $this->book = $this->createBookNode('new');
    $book = $this->book;

    /* * Add page hierarchy to book. * Book * |- Node 0 * |- Node 1 * |- Node 2 * |- Node 3 * |- Node 4 * |- Node 5 * |- Node 6 */

  public function createBook($edit = []) {
    // Create new book.     $this->drupalLogin($this->bookAuthor);

    $this->book = $this->createBookNode('new', NULL, $edit);
    $book = $this->book;

    /* * Add page hierarchy to book. * Book * |- Node 0 * |- Node 1 * |- Node 2 * |- Node 3 * |- Node 4 */
    
$this->assertSession()->responseContains('[route.book_navigation]=0|2|6');
    $this->drupalGet($book_nodes[4]->toUrl());
    $this->assertSession()->responseContains('[route.book_navigation]=0|2|7');
  }

  /** * Tests saving the book outline on an empty book. */
  public function testEmptyBook() {
    // Create a new empty book.     $this->drupalLogin($this->bookAuthor);
    $book = $this->createBookNode('new');
    $this->drupalLogout();

    // Log in as a user with access to the book outline and save the form.     $this->drupalLogin($this->adminUser);
    $this->drupalGet('admin/structure/book/' . $book->id());
    $this->submitForm([], 'Save book pages');
    $this->assertSession()->pageTextContains('Updated book ' . $book->label() . '.');
  }

  /** * Tests book functionality through node interfaces. */

    ViewTestData::createTestViews(static::class['book_test_views']);
  }

  /** * Creates a new book with a page hierarchy. */
  protected function createBook() {
    // Create new book.     $this->drupalLogin($this->bookAuthor);

    $this->book = $this->createBookNode('new');
    $book = $this->book;

    $nodes = [];
    // Node 0.     $nodes[] = $this->createBookNode($book->id());
    // Node 1.     $nodes[] = $this->createBookNode($book->id()$nodes[0]->book['nid']);
    // Node 2.     $nodes[] = $this->createBookNode($book->id()$nodes[1]->book['nid']);
    // Node 3.     $nodes[] = $this->createBookNode($book->id()$nodes[2]->book['nid']);
    
Home | Imprint | This part of the site doesn't use cookies.