/**
  * Generates HTML for export when invoked by book_export().
  *
  * The given node is embedded to its absolute depth in a top level section. For
  * example, a child node with depth 2 in the hierarchy is contained in
  * (otherwise empty) <div> elements corresponding to depth 0 and depth 1.
  * This is intended to support WYSIWYG output - e.g., level 3 sections always
  * look like level 3 sections, no matter their depth relative to the node
  * selected to be exported as printer-friendly HTML.
  *
  * @param \Drupal\node\NodeInterface $node
  *   The node to export.
  *
  * @throws \Exception
  *   Thrown when the node was not attached to a book.
  *
  * @return array
  *   A render array representing the HTML for a node and its children in the
  *   book hierarchy.
  */
 public function bookExportHtml(NodeInterface $node)
 {
     if (!isset($node->book)) {
         throw new \Exception();
     }
     $tree = $this->bookManager->bookSubtreeData($node->book);
     $contents = $this->exportTraverse($tree, array($this, 'bookNodeExport'));
     return array('#theme' => 'book_export_html', '#title' => $node->label(), '#contents' => $contents, '#depth' => $node->book['depth'], '#cache' => ['tags' => $node->getEntityType()->getListCacheTags()]);
 }
Esempio n. 2
0
 /**
  * Gets a list of node revision IDs for a specific node.
  *
  * @param \Drupal\node\NodeInterface
  *   The node entity.
  * @param \Drupal\node\NodeStorageInterface $node_storage
  *   The node storage handler.
  *
  * @return int[]
  *   Node revision IDs (in descending order).
  */
 protected function _getRevisionIds(NodeInterface $node, NodeStorageInterface $node_storage)
 {
     $result = $node_storage->getQuery()->allRevisions()->condition($node->getEntityType()->getKey('id'), $node->id())->sort($node->getEntityType()->getKey('revision'), 'DESC')->pager(50)->execute();
     return array_keys($result);
 }