Given a book node nid, programmatically get all child node nids 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.
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-&gt;loadBookChildren(NID);