BookManager::getBookParents

public BookManager::getBookParents(array $item, array $parent = array())

Overrides BookManagerInterface::getBookParents

File

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

Class

BookManager
Defines a book manager.

Namespace

Drupal\book

Code

public function getBookParents(array $item, array $parent = array()) {
  $book = array();
  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;
}
doc_Drupal
2016-10-29 08:48:11
Comments
Leave a Comment

Please login to continue.