function BookManager::getBookParents

Same name in other branches
  1. 8.9.x core/modules/book/src/BookManager.php \Drupal\book\BookManager::getBookParents()
  2. 10 core/modules/book/src/ProxyClass/BookManager.php \Drupal\book\ProxyClass\BookManager::getBookParents()
  3. 10 core/modules/book/src/BookManager.php \Drupal\book\BookManager::getBookParents()
  4. 11.x core/modules/book/src/ProxyClass/BookManager.php \Drupal\book\ProxyClass\BookManager::getBookParents()
  5. 11.x core/modules/book/src/BookManager.php \Drupal\book\BookManager::getBookParents()

Overrides BookManagerInterface::getBookParents

1 call to BookManager::getBookParents()
BookManager::saveBookLink in core/modules/book/src/BookManager.php
Saves a link for a single book entry to the book.

File

core/modules/book/src/BookManager.php, line 371

Class

BookManager
Defines a book manager.

Namespace

Drupal\book

Code

public function getBookParents(array $item, array $parent = []) {
    $book = [];
    if ($item['pid'] == 0) {
        $book['p1'] = $item['nid'];
        for ($i = 2; $i <= static::BOOK_MAX_DEPTH; $i++) {
            $parent_property = "p{$i}";
            $book[$parent_property] = 0;
        }
        $book['depth'] = 1;
    }
    else {
        $i = 1;
        $book['depth'] = $parent['depth'] + 1;
        while ($i < $book['depth']) {
            $p = 'p' . $i++;
            $book[$p] = $parent[$p];
        }
        $p = 'p' . $i++;
        // The parent (p1 - p9) corresponding to the depth always equals the nid.
        $book[$p] = $item['nid'];
        while ($i <= static::BOOK_MAX_DEPTH) {
            $p = 'p' . $i++;
            $book[$p] = 0;
        }
    }
    return $book;
}

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