I use the D8 Book module to create books with chapters. Works great.

When an editor makes a certain change to a book node, I need to look at each of its chapter (child) nodes to potentially adjust a field in them.

I know how to detect the book node change in node_presave(). I know how to load, modify, and save a child node once I have its nid. What I don't know is how to get a complete list child node nids for the book.

I've read many posts related to this subject, but none that provide a straightforward way to programmatically get a list of child node nids given the parent book node nid. I've also looked at the Book module documentation. I assume I'm just overlooking something simple.

1 Answer 1


To get the complete list of child node nids for the book:
use the BookOutlineStorage::loadBookChildren from the book.outline_storage service. like the following:

/** @var \Drupal\book\BookOutlineStorageInterface $book_outline_storage */
$book_outline_storage = \Drupal::service('book.outline_storage');
$childrens  =  $book_outline_storage->loadBookChildren(NID);
  • Thanks so much @berramou! So easy, and yet nearly impossible without your help. Sep 30, 2020 at 0:11
  • you are welcome @MarshallMorrise i'm glad that helps !
    – berramou
    Sep 30, 2020 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.