You are here

public function BookManager::getBookParents in Drupal 9

Same name and namespace in other branches
  1. 8 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 single book entry.

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;
}