function BookManager::getBookParents

Same name in this branch
  1. 11.x core/modules/book/src/ProxyClass/BookManager.php \Drupal\book\ProxyClass\BookManager::getBookParents()
Same name and namespace in other branches
  1. 9 core/modules/book/src/BookManager.php \Drupal\book\BookManager::getBookParents()
  2. 8.9.x core/modules/book/src/BookManager.php \Drupal\book\BookManager::getBookParents()
  3. 10 core/modules/book/src/ProxyClass/BookManager.php \Drupal\book\ProxyClass\BookManager::getBookParents()
  4. 10 core/modules/book/src/BookManager.php \Drupal\book\BookManager::getBookParents()
1 call to BookManager::getBookParents()
BookManager::saveBookLink in core/modules/book/src/BookManager.php

File

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

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.