diff -u b/core/modules/book/src/BookOutlineStorage.php b/core/modules/book/src/BookOutlineStorage.php --- b/core/modules/book/src/BookOutlineStorage.php +++ b/core/modules/book/src/BookOutlineStorage.php @@ -27,8 +27,12 @@ /** * Constructs a BookOutlineStorage object. */ - public function __construct(Connection $connection, AccountInterface $currentUser) { + public function __construct(Connection $connection, AccountInterface $currentUser = NULL) { $this->connection = $connection; + if (!$currentUser) { + @trigger_error('The current_user service must be passed to ' . __NAMESPACE__ . '\BookOutlineStorage::__construct(). It was added in drupal:8.9.0 and will be required before drupal:10.0.0.', E_USER_DEPRECATED); + $currentUser = \Drupal::service('current_user'); + } $this->currentUser = $currentUser; } @@ -36,9 +40,14 @@ * {@inheritdoc} */ public function getBooks() { + $currentUserId = $this->currentUser->id(); if ($this->currentUser->hasPermission('view any unpublished content')) { return $this->connection->query("SELECT DISTINCT(bid) FROM {book}")->fetchCol(); - } else { + } + elseif ($this->currentUser->hasPermission('view own unpublished content')) { + return $this->connection->query("SELECT DISTINCT(bid) FROM {book} b INNER JOIN {node_field_data} f ON b.nid = f.nid WHERE f.uid = $currentUserId OR f.status = 1")->fetchCol(); + } + else { return $this->connection->query("SELECT DISTINCT(bid) FROM {book} b INNER JOIN {node_field_data} f ON b.nid = f.nid WHERE f.status = 1")->fetchCol(); } }